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
1. Take all the intervals and do an "events" (or "line sweep") approach - an event of (x, OPEN) increases the number of active intervals, while (x, CLOSE) decreases it.
20
+
<details>
21
+
<summary>Hint 1</summary>
22
+
Take all the intervals and do an "events" (or "line sweep") approach - an event of (x, OPEN) increases the number of active intervals, while (x, CLOSE) decreases it.
21
23
22
24
Processing in sorted order from left to right, if the number of active intervals is zero, then you crossed a region of common free time.
Copy file name to clipboardExpand all lines: problems/find-minimum-in-rotated-sorted-array/README.md
+12-3Lines changed: 12 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,10 +38,19 @@
38
38
1.[Find Minimum in Rotated Sorted Array II](https://github.com/openset/leetcode/tree/master/problems/find-minimum-in-rotated-sorted-array-ii) (Hard)
39
39
40
40
### Hints
41
-
1. Array was originally in ascending order. Now that the array is rotated, there would be a point in the array where there is a small deflection from the increasing sequence. eg. The array would be something like [4, 5, 6, 7, 0, 1, 2].
42
-
1. You can divide the search space into two and see which direction to go.
41
+
<details>
42
+
<summary>Hint 1</summary>
43
+
Array was originally in ascending order. Now that the array is rotated, there would be a point in the array where there is a small deflection from the increasing sequence. eg. The array would be something like [4, 5, 6, 7, 0, 1, 2].
44
+
</details>
45
+
<details>
46
+
<summary>Hint 2</summary>
47
+
You can divide the search space into two and see which direction to go.
43
48
Can you think of an algorithm which has O(logN) search complexity?
44
-
1. <ol>
49
+
</details>
50
+
<details>
51
+
<summary>Hint 3</summary>
52
+
<ol>
45
53
<li>All the elements to the left of inflection point > first element of the array.</li>
46
54
<li>All the elements to the right of inflection point < first element of the array.</li>
1. Use two pointers to create a window of letters in <b>S</b>, which would have all the characters from <b>T</b>.
41
-
1. Since you have to find the minimum window in <b>S</b> which has all the characters from <b>T</b>, you need to expand and contract the window using the two pointers and keep checking the window for all the characters. This approach is also called Sliding Window Approach.
40
+
<details>
41
+
<summary>Hint 1</summary>
42
+
Use two pointers to create a window of letters in <b>S</b>, which would have all the characters from <b>T</b>.
43
+
</details>
44
+
<details>
45
+
<summary>Hint 2</summary>
46
+
Since you have to find the minimum window in <b>S</b> which has all the characters from <b>T</b>, you need to expand and contract the window using the two pointers and keep checking the window for all the characters. This approach is also called Sliding Window Approach.
42
47
43
48
<br><br>
44
49
<pre>
@@ -47,3 +52,4 @@ L ------------------------ R , Suppose this is the window that contains all char
47
52
        L----------------- R , this is the contracted window. We found a smaller window that still contains all the characters in <b>T</b>
48
53
49
54
When the window is no longer valid, start expanding again using the right pointer. </pre>
1. How can we reuse a previously computed palindrome to compute a larger palindrome?
51
-
1. If "aba" is a palindrome, is "xabax" and palindrome? Similarly is "xabay" a palindrome?
52
-
1. Complexity based hint:</br>
50
+
<details>
51
+
<summary>Hint 1</summary>
52
+
How can we reuse a previously computed palindrome to compute a larger palindrome?
53
+
</details>
54
+
<details>
55
+
<summary>Hint 2</summary>
56
+
If "aba" is a palindrome, is "xabax" and palindrome? Similarly is "xabay" a palindrome?
57
+
</details>
58
+
<details>
59
+
<summary>Hint 3</summary>
60
+
Complexity based hint:</br>
53
61
If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end pairs and O(n) palindromic checks. Can we reduce the time for palindromic checks to O(1) by reusing some previous computation?
1.* If the expression starts with a digit or '-', it's an integer: return it.
82
+
<details>
83
+
<summary>Hint 1</summary>
84
+
* If the expression starts with a digit or '-', it's an integer: return it.
83
85
84
86
* If the expression starts with a letter, it's a variable. Recall it by checking the current scope in reverse order.
85
87
@@ -88,3 +90,4 @@ of the final x in the add-expression. That final x will equal 2.
88
90
* For add and mult expressions, evaluate each token and return the addition or multiplication of them.
89
91
90
92
* For let expressions, evaluate each expression sequentially and assign it to the variable in the current scope, then return the evaluation of the final expression.
1. Since we don't know which of the brackets can possibly be removed, we try out all the options!
44
-
1. We can use recursion to try out all possibilities for the given expression. For each of the brackets, we have 2 options:
43
+
<details>
44
+
<summary>Hint 1</summary>
45
+
Since we don't know which of the brackets can possibly be removed, we try out all the options!
46
+
</details>
47
+
<details>
48
+
<summary>Hint 2</summary>
49
+
We can use recursion to try out all possibilities for the given expression. For each of the brackets, we have 2 options:
45
50
46
51
<ol>
47
52
<li> We keep the bracket and add it to the expression that we are building on the fly during recursion.</li>
48
53
<li> OR, we can discard the bracket and move on.
49
54
</ol>
50
-
1. The one thing all these valid expressions have in common is that they will all be of the same length i.e. as compared to the original expression, all of these expressions will have the same number of characters removed.
55
+
</details>
56
+
<details>
57
+
<summary>Hint 3</summary>
58
+
The one thing all these valid expressions have in common is that they will all be of the same length i.e. as compared to the original expression, all of these expressions will have the same number of characters removed.
51
59
52
60
Can we somehow find the number of misplaced parentheses and use it in our solution?
53
-
1. The one thing all these valid expressions have in common is that they will all be of the same length i.e. as compared to the original expression, all of these expressions will have the same number of characters removed.
61
+
</details>
62
+
<details>
63
+
<summary>Hint 4</summary>
64
+
The one thing all these valid expressions have in common is that they will all be of the same length i.e. as compared to the original expression, all of these expressions will have the same number of characters removed.
54
65
55
66
Can we somehow find the number of misplaced parentheses and use it in our solution?
56
-
1. For every left parenthesis, we should have a corresponding right parenthesis. We can make use of two counters which keep track of misplaced left and right parenthesis and in one iteration we can find out these two values.
67
+
</details>
68
+
<details>
69
+
<summary>Hint 5</summary>
70
+
For every left parenthesis, we should have a corresponding right parenthesis. We can make use of two counters which keep track of misplaced left and right parenthesis and in one iteration we can find out these two values.
57
71
58
72
<pre>
59
73
0 1 2 3 4 5 6 7
@@ -69,4 +83,8 @@ i = 7, left = 2, right = 2
69
83
</pre>
70
84
71
85
We have 2 misplaced left and 2 misplaced right parentheses.
72
-
1. We found out that the exact number of left and right parenthesis that has to be removed to get a valid expression. So, e.g. in a 1000 parentheses string, if there are 2 misplaced left and 2 misplaced right parentheses, after we are done discarding 2 left and 2 right parentheses, we will have only one option per remaining character in the expression i.e. to consider them. We can't discard them.
86
+
</details>
87
+
<details>
88
+
<summary>Hint 6</summary>
89
+
We found out that the exact number of left and right parenthesis that has to be removed to get a valid expression. So, e.g. in a 1000 parentheses string, if there are 2 misplaced left and 2 misplaced right parentheses, after we are done discarding 2 left and 2 right parentheses, we will have only one option per remaining character in the expression i.e. to consider them. We can't discard them.
0 commit comments