Problems


August 2, 2022

Permutation in string

We will first count the characters in string1 and then we will slide a window of length of string1 and count the matches of the characters of string1 and sliding window. If the number of matches is...

Read

August 2, 2022

Kth smallest element in a sorted matrix

We will create a max heap and insert each element there. If the length of the heap is more than k, we pop item from the heap. After the iteration is done, we return to top of the heap. As python does...

Read

August 1, 2022

Copy list with random pointer

We will traverse the whole list twice, first time we create a hashmap to store all the nodes without any linking. Then we traverse it again, but this time, as we already have all the nodes, we will...

Read

August 1, 2022

Koko eating bananas

We will search through each position of the piles till the largest pile, where it allows us to eat all the bananas within given h hours. We can do it in brute force, but if we search with binary...

Read

August 1, 2022

Add two numbers

We will add first node from both list, and add it to a new list. We will also keep a carry if the number if greater than 9. We will run it until all of l1, l2 and carry is null and return the head of...

Read

August 1, 2022

Reorder list

We will first find the middle of the list with a fast and slow pointer, fast pointer is twice as fast as the slow pointer. Then we will reverse the second half of the linked list. Finally, we merge...

Read

July 31, 2022

Perfect squares

This problem is exactly like the coin change problem. But we are not given a list of squares, we need to generate it. The biggest squares root will be the square root of the given number, without any...

Read

July 31, 2022

reverse-integer

We can get the least significant digit by moding it with 10. Then we can also get the remainder of the number by divide it by 10. The only catch of this problem is if the reversed number overflows 32...

Read

July 31, 2022

Min cost climbing stairs

We will follow the similar approach as Climbing stairs, first solve it with recursion, the use memoization to make it efficient. If the number of stairs is less than 0, then the cost of climbing it...

Read

July 31, 2022

Sum of two integers

We know, 2^a + 2^b = 2^(a+b) and log2(2^a) = a. We can use this two formula to sum 2 numbers without using +. Time Complexity: O(1) Space...

Read
... 81 82 83 84 85 ...