You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+26-13
Original file line number
Diff line number
Diff line change
@@ -9,33 +9,46 @@ I commit a lot, many a times unnecessarily in this repo, it could be better solu
9
9
10
10
| # | Hints | Complexity |
11
11
|---| ----- | ---------- |
12
-
| 5 | Build recurrence relation (may help to solve longest common substring problem) |. |
13
-
| 15 | Solve 2 sum before attempting this problem. |. |
14
-
| 17 | Possible approaches are trie, or more easy - building on smaller solution. ||
15
-
| 22 | If less than n open brackets are open, we can add open bracket. But to add a close bracket you need count(')') < count('(') | .|
16
-
| 23 | Use a data structure which can give you minimum element at low cost.|. |
17
-
| 26 | Maintain length of unique elements till current element.|.|
18
-
| 27 | vector.erase() will not work, as vector overwrites the element every time erase is called.|. |
19
-
| 28 | Brute force. | .|
20
-
| 31 | Find the location closest from the end which has segment ab of the form a < b, and make it ba. | .|
21
-
| 33 | Array increasing, sudden drop and then increasing again. Find out where the middle element is, can it's location help you? | .|
12
+
| 1 | Use hash map to store all values until current value. | O(n) |
13
+
| 2 | Brute force. | O(n) |
14
+
| 3 | Use a window. Extend if next element is not in the current window. | O(n) |
15
+
| 5 | Build recurrence relation (may help to solve longest common substring problem) | O(n^2) |
16
+
| 7 | Brute force. | O(log(n)) |
17
+
| 9 | Brute force. | O(log(n)) |
18
+
| 10 | Use a 2D matrix. DP[i][j] = whether p[0:i] matches with str[0:j]. | O(mn) |
19
+
| 15 | Solve 2 sum before attempting this problem. | O(n^2) |
20
+
| 16 | Similar to 3 sum, but use a sorted array and make front++, back-- updates to minimize abs(target - sum). | O(n^2) |
21
+
| 17 | Possible approaches are trie, or more easy - building on smaller solution. | O(4^n)|
22
+
| 22 | If less than n open brackets are open, we can add open bracket. But to add a close bracket you need count(')') < count('(') | . |
23
+
| 23 | Use a data structure which can give you minimum element at low cost.| . |
24
+
| 26 | Maintain length of unique elements till current element.| O(n)|
25
+
| 27 | vector.erase() will not work, as vector overwrites the element every time erase is called.| O(n)|
26
+
| 28 | Brute force. | O(mn) |
27
+
| 31 | Find the location closest from the end which has segment ab of the form a < b, and make it ba. | O(n log(n))|
28
+
| 33 | Array increasing, sudden drop and then increasing again. Find out where the middle element is, can it's location help you? | O(log(n))|
22
29
| 36 | Brute force.| O(1)|
23
30
| 42 | Find next greater element index for each index, and prefix sum for each element. Can you build the solution from this? Check out problem 496 for next greater element. ||
31
+
| 43 | Normal multiplication, like in school. | O(n log(d)) |
32
+
| 44 | Solve problem 10 first. Construct a 2D box of size len(pattern)*len(string). DP[i][j] = whether p[0:i] matches with str[0:j]| O(mn) |
33
+
| 46 | Combine str[0] with permutations of str[1:], use recursion. | O(n!) |
34
+
| 47 |
24
35
| 108 | Where does the root element fall during an inorder (sorted) traversal? ||
25
36
| 128 | DP problem, find recurrence relation. ||
26
37
27
38
## Second hint list
28
39
29
40
| # | Hints | Complexity |
30
41
|---| ----- | ---------- |
31
-
| 5 | Use DP, P<i, j> = P<i+1, j-1> && S[i] == S[j] is the recurrence relation.||
32
-
| 15 | 2sum for a sorted list gives a more optimal sub routine here. ||
33
-
| 17 | Build solution for first k numbers, and modify solution vector for k+1 number. ||
42
+
| 5 | Use DP, P<i, j> = P<i+1, j-1> && S[i] == S[j] is the recurrence relation.| O(n^2) |
0 commit comments