Problems
July 24, 2022
Longest substring without repeating characters
We will use a set to keep track of repeating characters. We will have 2 pointers, we will move our right pointer, check if the character as right pointer is already exist in the set, if exists, then...
ReadJuly 24, 2022
Implement queue using stacks
We will have 2 stack, one for input, one for output. Whenever we push anything, we push it to the input stack, then pop every element from input stack and push it back to output stack. Every other...
ReadJuly 24, 2022
Search a 2d matrix II
if the current grid value matrix[r][c] is less than the target, that means, we don't need to search in this row anymore, as all the values are already bigger than the matrix[r][c]. If the value is...
ReadJuly 24, 2022
Word search
We will run dfs on each element of the board, if we find a character match, then we move forward and search for next character in all 4 directions.
Time Complexity: O(n*m*4^n)
Space...
July 24, 2022
Permutations II
First we will count the number of each element, then we create our decision tree, if we take one element, then we remove that element form our count hashmap. If it has multiple instance, we reduce...
ReadJuly 24, 2022
Subsets II
We will first sort the element. Then like the original subset problem, we will have 2 choice for each element, either choose it or skip it. As we don't want duplicate subset, we will skip the same...
ReadJuly 23, 2022
3Sum
If you already solved the 2 sum ii problem, you might get the idea. First we will sort the list. Then we take the first element at first position, then for the rest of the elements we take 2...
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 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,...
Read