Problems


December 20, 2022

Minimum initial energy to finish tasks

We will sort the tasks by the difference between the cost and the energy. We will iterate through the tasks and keep track of the current energy. If the current energy is less than the cost of the...

Read

December 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...

Read

December 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...

Read

December 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...

Read

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...

Read

December 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...

Read

December 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)...

Read

December 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...

Read

December 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...

Read

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...

Read
... 15 16 17 18 19 ...