Problems
December 20, 2022
Ways to make a fair array
We will use odd prefix and even prefix to keep track of the sum of the odd and even indices. We will iterate through the array and keep track of the odd and even prefix. We will use a helper function...
ReadDecember 20, 2022
Backspace string compare
We will create a helper function that will take a string and return the string after applying the backspace operation. To evaluate, we will append each character to a stack, and whenever we hit a...
ReadDecember 20, 2022
Longest mountain in array
We will use two pointers to keep track of the start and end of the mountain. We will iterate through the array and keep track of the start and end of the mountain. If the current element is greater...
ReadDecember 20, 2022
Shifting letters
We will calculate the total shift and then shift each character by the total shift. We will keep track of the total shift by subtracting the shift from the total shift. We will use a helper function...
ReadDecember 19, 2022
Maximum number of books you can take
Use stack to find how long a consecutive ramp can be built at each index. Previous higher shelves are popped out of the stack since they do not impact how long we can build. If ramp terminated by a...
ReadDecember 19, 2022
Delete n nodes after m nodes of a linked list
We will create a dummy node and attach the head node to it. Then we will do the following: Use an indicator i to count the number of already-passed list nodes Keep moving head node forward as long...
ReadDecember 19, 2022
Clone binary tree with random pointer
We will use a hashmap to store the mapping between the original node and the cloned node. Then we will iterate over the hashmap and clone the random pointer.
Time complexity: O(n)
...
December 19, 2022
Decode the message
We will use a hashmap to map the characters to their corresponding letters. Then iterate over the message, replace the characters with their corresponding letters and return the result. Time...
ReadDecember 19, 2022
Path crossing
We will start with the origin (0, 0)
and for each move we will update the current position. If the current position is already in the set of visited positions, then we have a path...
December 19, 2022
Check if array pairs are divisible by k
We will use a hashmap to store the frequency of each remainder. Then we will iterate over the hashmap and check if the remainder is divisible by k
. If it is, then we will check if the...