Problems
October 9, 2022
Convert bst to greater tree
We will iterate over the tree in reverse inorder and keep track of the sum of all the nodes we have traversed so far. We will add the sum to the current node and update the sum with the current node...
ReadOctober 9, 2022
Guess number higher or lower
This is a classic binary search problem. We will use binary search to find the number. We will use provided guess
function to check whether the number is equal to the target or not....
October 8, 2022
Remove element
We will take a pointer at the beginning of the array, then iterate over the whole array. If the value doesn't match the given values, we assing it to the pointer's position of the array and then...
ReadOctober 8, 2022
Find all anagrams in a string
We will use counter to calculate the number of characters of string p. Then we take a sliding window of lenght p, then compare the character count with the character count of p. If we found a match,...
ReadOctober 8, 2022
Find the index of the first occurrence in a string
We will create a substring of length of the needle and compare it with the needle, if we find a match, we return the index as result, otherwise return -1.
Time Complexity: O(n)
Space...
October 8, 2022
Unique length 3 palindromic subsequences
For each palindromes in format of "aba", we enumerate the character on two side. We find its first occurrence and its last occurrence, all the characters in the middle are the candidate for the...
ReadOctober 7, 2022
Single threaded cpu
First we sort the tasks according to start time, remember to keep a reference to the original task index. Set the current time to the first start time in the task list. Push all tasks whose start...
ReadOctober 7, 2022
Search insert position
This one is the classic binary search problem. We will strat looking for the target, if we find the target then we insert on that position. If we don't find the target, then we insert at the last low...
ReadOctober 7, 2022
Reverse linked list II
First if the left and right position of the list is same, we can just return the list. Otherwise, we will take a pointer, traverse till the left position, then reverse the list in place till the...
ReadOctober 6, 2022
Longest common prefix
We will take the shortest string as the shortest at the beginning. Then we iterate over each character of the shortest string, and match with the other strings, if the character doesn't match, we...
Read