Problems
July 23, 2022
Last stone weight
We will use a max heap and then pop 2 element at a time and simulate the problem statement. As python doesn't have any max heap, we will use the min heap but multiply each element with -1 and the the...
ReadJuly 23, 2022
Meeting rooms II
We will sort the intervals, then in each iteration we will compare the end of the meeting with the start of the previous meeting. We will keep track of the count for the number of meeting going on,...
ReadJuly 23, 2022
Plus one
First we reverse the list, then add one to the fist item, if the number is 9, then we keep a carry and add it to the next number. We will do that until all the digit in the list have been iterated...
ReadJuly 23, 2022
Remove nth node from end of list
We will have 2 pointer, first we move the right pointer to nth node. Then we move both left and right pointer until the right pointer moves to the end of the list, that means left pointer is now on...
ReadJuly 23, 2022
Subsets
We will do backtracking to solve the result. For each element of the list, we have 2 option, either we take the element or we leave the element. From this base case, if we run dfs for from the...
ReadJuly 23, 2022
Task scheduler
We will first count each characters and create a max heap out of it. Then we pop the item from the heap, put it on a queue, and increase the value of our counter. Then we process the task, if there...
ReadJuly 23, 2022
Time based key value store
We will keep a hashmap as the key value store, key will be used as the key, value will have an array storing all the values and timestamp. When we search for the value, we will look up in the store...
ReadJuly 22, 2022
Jump game II
This is very similar to jump game, we will go for a greedy approah. We will have 2 pointer, left and right to determine the level of each move. In every iteration we will calculate the maximum number...
ReadJuly 22, 2022
Jump game
This problem could definitely be solved by dynamic programming, but if we take greedy approach, we can solve it in linear time. We can iterate through the array from last index to first index. We set...
Read