Nan-Do commited on
Commit
401dc60
1 Parent(s): d1b4b56

Update README.md

Browse files

Updated README.md with some examples generated by the model.

Files changed (1) hide show
  1. README.md +115 -36
README.md CHANGED
@@ -9,6 +9,89 @@ tags:
9
  - CP
10
  ---
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  ```
13
  Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
14
 
@@ -16,58 +99,54 @@ Below is an instruction that describes a task, paired with an input that provide
16
  Solve the problem using Python.
17
 
18
  ### Input:
19
- Consider a matrix M with dimensions width * height, such that every cell has value 0 or 1, and any square sub-matrix of M of size sideLength * sideLength has at most maxOnes ones.
 
 
 
 
 
 
20
 
21
- Return the maximum possible number of ones that the matrix M can have.
22
 
23
-
24
 
25
  Example 1:
26
 
27
- Input: width = 3, height = 3, sideLength = 2, maxOnes = 1
28
- Output: 4
29
- Explanation:
30
- In a 3*3 matrix, no 2*2 sub-matrix can have more than 1 one.
31
- The best solution that has 4 ones is:
32
- [1,0,1]
33
- [0,0,0]
34
- [1,0,1]
35
 
36
  Example 2:
37
 
38
- Input: width = 3, height = 3, sideLength = 2, maxOnes = 2
39
- Output: 6
40
- Explanation:
41
- [1,0,1]
42
- [1,0,1]
43
- [1,0,1]
44
 
45
-
46
 
47
  Constraints:
48
 
49
- 1 <= width, height <= 100
50
- 1 <= sideLength <= width, height
51
- 0 <= maxOnes <= sideLength * sideLength
52
 
53
 
54
 
55
  ### Response:
56
- Sure, here you have a possible implementation to solve the problem.
57
-
58
  '''python
59
- class Solution:
60
- def maximumNumberOfOnes(self, C, R, K, maxOnes):
61
- # every K*K square has at most maxOnes ones
62
- count = [0] * (K*K)
63
- for r in range(R):
64
- for c in range(C):
65
- code = (r%K) * K + c%K
66
- count[code] += 1
67
- count.sort()
68
- ans = 0
69
- for _ in range(maxOnes):
70
- ans += count.pop()
71
- return ans
72
  '''
73
  ```
 
9
  - CP
10
  ---
11
 
12
+ This model is a fine-tuned version of the [WizardCoder-Python-7B](https://huggingface.co/WizardLM/WizardCoder-Python-7B-V1.0) with a dataset of [Leetcode](https://leetcode.com/) problems.
13
+ It should be able to solve most of the problems at Leetcode and even pass the sample interviews they offer on the site.
14
+
15
+ It can write both code and explanations for the solutions.
16
+
17
+ This is the result of one of the Google's phone interviews.
18
+ Question 1:
19
+ ```
20
+ Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
21
+
22
+ ### Instruction:
23
+ Solve the problem using Python 3 and explain your solution.
24
+
25
+ ### Input:
26
+ Given an array of integers arr, return true if the number of occurrences of each value in the array is unique or false otherwise.
27
+
28
+
29
+
30
+ Example 1:
31
+
32
+ Input: arr = [1,2,2,1,1,3]
33
+ Output: true
34
+ Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1. No two values have the same number of occurrences.
35
+
36
+ Example 2:
37
+
38
+ Input: arr = [1,2]
39
+ Output: false
40
+
41
+ Example 3:
42
+
43
+ Input: arr = [-3,0,1,-3,1,1,1,-3,10,0]
44
+ Output: true
45
+
46
+
47
+
48
+ Constraints:
49
+
50
+ 1 <= arr.length <= 1000
51
+ -1000 <= arr[i] <= 1000
52
+
53
+ ### Response:
54
+ Sure, here you have an explanation for the problem.
55
+ ## Solution Article
56
+ ---
57
+ #### Approach 1: Counting Sort
58
+
59
+ **Intuition**
60
+
61
+ If we knew the frequency of every element in `arr`, then we could check that they are all unique by checking that there was only one occurrence of each frequency. However, this would be very expensive to do manually.
62
+
63
+ Fortunately, we don't need to count the elements themselves; we just need to know how many times each *frequency* occurred.
64
+
65
+ So let's count the frequencies. We can use a simple linear scan for this. After, we should check that there was only one occurrence of each frequency.
66
+
67
+ **Algorithm**
68
+
69
+ First, perform a linear scan to count the frequencies of each element. Our result will be an array where `count[k]` is the number of occurrences of the $$k$$-th element.
70
+
71
+ Afterwards, we should check that there was only one occurrence of each frequency. If any two entries in `count` have the same value (representing the same frequency), then our answer is `False`. Otherwise, our answer is `True`.
72
+
73
+
74
+
75
+ '''python
76
+ class Solution(object):
77
+ def uniqueOccurrences(self, A):
78
+ count = collections.Counter(A)
79
+ seen = set()
80
+ for k, v in count.iteritems():
81
+ if v in seen: return False
82
+ seen.add(v)
83
+ return True
84
+ '''
85
+
86
+
87
+ **Complexity Analysis**
88
+
89
+ * Time Complexity: $$O(N)$$, where $$N$$ is the length of `A`.
90
+
91
+ * Space Complexity: $$O(N)$$ in additional space complexity, to store the `count`.
92
+ ```
93
+
94
+ Question 2:
95
  ```
96
  Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
97
 
 
99
  Solve the problem using Python.
100
 
101
  ### Input:
102
+ You have n boxes. You are given a binary string boxes of length n, where boxes[i] is '0' if the ith box is empty, and '1' if it contains one ball.
103
+
104
+ In one operation, you can move one ball from a box to an adjacent box. Box i is adjacent to box j if abs(i - j) == 1. Note that after doing so, there may be more than one ball in some boxes.
105
+
106
+ Return an array answer of size n, where answer[i] is the minimum number of operations needed to move all the balls to the ith box.
107
+
108
+ Each answer[i] is calculated considering the initial state of the boxes.
109
 
 
110
 
 
111
 
112
  Example 1:
113
 
114
+ Input: boxes = "110"
115
+ Output: [1,1,3]
116
+ Explanation: The answer for each box is as follows:
117
+ 1) First box: you will have to move one ball from the second box to the first box in one operation.
118
+ 2) Second box: you will have to move one ball from the first box to the second box in one operation.
119
+ 3) Third box: you will have to move one ball from the first box to the third box in two operations, and move one ball from the second box to the third box in one operation.
 
 
120
 
121
  Example 2:
122
 
123
+ Input: boxes = "001011"
124
+ Output: [11,8,5,4,3,4]
125
+
 
 
 
126
 
 
127
 
128
  Constraints:
129
 
130
+ n == boxes.length
131
+ 1 <= n <= 2000
132
+ boxes[i] is either '0' or '1'.
133
 
134
 
135
 
136
  ### Response:
137
+ Of course, here is an example of a solution using Python that provides a solution to the problem.
 
138
  '''python
139
+ class Solution(object):
140
+ def minOperations(self, s):
141
+ """
142
+ :type boxes: str
143
+ :rtype: List[int]
144
+ """
145
+ n = len(s)
146
+ pos = []
147
+ for i, c in enumerate(s):
148
+ if c == '1':
149
+ pos.append(i)
150
+ return [sum(abs(j-i) for j in pos) for i in xrange(n)]
 
151
  '''
152
  ```