My code can be viewed in my github: Proverbs Github.
The following difficulty is defined by myself.
beautiful-array(hard)
It is hard because the first time I see this problem, I didn’t have any idea of how to solve it.
Then, it the discuss, I found a quite brilliant way which is kind of like a reversion divide and conquer.
Divide the range to the odd part and the even part. Combining with the two properties, we can scale down the problem.
Link.
- Time complexity: O(n) with cache.
- Space complexity: O(n).
expressive-words(easy)
O(n) for enumerating groups, O(n) for checking if one group can extend to another.
- Time complexity: O(n^2).
- Space complexity: O(1)
logger-rate-limiter(easy)
Use a map to save the timestamp.
- Time complexity: O(1).
- Space complexity: O(n).
longest-word-in-dictionary-through-deleting(easy)
O(n) for enumerating words, O(word.length) for checking if the word is the subsequence of the given string.
- Time complexity: O(n * word.length).
- Space complexity: O(1).
minesweeper(easy)
Recursion. Just do as the description.
- Time complexity: O(len * col).
- Space complexity: O(len * col).
most-stones-removed-with-same-row-or-column(hard)
It quite easy to go into a incorrect greedy solution which can be seen in my github.
A counter example.
The correct solution is to find components.
There are two key insights:
- Connected stones can be reduced to 1 stone.
- the maximum stones can be removed = stones number - islands number.
- Time complexity: O(n).
- Space complexity: O(n).
print-binary-tree(medium)
First, compute the size of the output.
Then, use divide and conquer. I think my solution is quite elegant. I mean, just for this problem. ^_^.
- Time complexity: O(2^h).
- Space complexity: O(h * 2^h).
self-dividing-numbers(easy)
Do as the description.
- Time complexity: O(digits * n).
- Space complexity: O(1).