Problems


October 29, 2022

Earliest possible day of full bloom

We can be greedy about the solution. We need to plant the flower that takes longest possible time to grow the earliest. So, we will sort the flowers in descending order of their grow time. Then we...

Read

October 29, 2022

Search in a binary search tree

We will traverse the tree in a depth-first manner. If the current node's value is equal to the target value, then we will return the current node. If the current node's value is greater than the...

Read

October 29, 2022

Most frequent number following key in an array

We will use a hashmap to store the frequency of each number. Then we will traverse the array and check if the current number is equal to the key. If it is, then we will increment the frequency of the...

Read

October 28, 2022

All elements in two binary search trees

We will inorder traverse both tree to get the sorted list of elements in both trees. We will merge the two sorted lists into one sorted list. Time complexity: O(n1+n2), n1 and n2 are...

Read

October 28, 2022

Sum of number and its reverse

We will try every number till the original given number, reverse the number and add it to the original number. Time complexity: O(n) Space complexity: O(1)

Read

October 28, 2022

Integer replacement

We will follow the problem statement, and solve it recursively. Then we will memoize the result to avoid repeated computations. Time complexity: O(n) Space complexity:...

Read

October 28, 2022

Fruit into baskets

We will use a sliding window to keep track of the fruits in the current basket. We will keep track of the last fruit we have seen and the number of times we have seen it. If the current fruit is the...

Read

October 28, 2022

Replace the substring for balanced string

We will use a sliding window to keep track of the number of characters in the current substring. We will keep track of the number of characters we need to replace. We will keep track of the minimum...

Read

October 28, 2022

Max consecutive ones

We will count the number of consecutive ones and update the result if it is greater than the current result. Time complexity: O(n) Space complexity: O(1)

Read

October 28, 2022

Max consecutive ones III

We basically need to find the longest subarray with at most k zeros. We can use the sliding window technique to get that. Time complexity: O(n) Space complexity: O(1)

Read
... 44 45 46 47 48 ...