Problems
January 5, 2023
Steps to make array non decreasing
Iterating the input A backward, then for each nums[i]
, find how many round it can eat on its right. dp[i]
means the number of element nums[i]
can eat on its...
January 4, 2023
Convert to base -2
We will use the following formula to convert a number n
to base -2
, where n
is a non-negative integer-
- Write a base 2 function
- If the number is odd, add 1...
January 4, 2023
Check if there is a valid path in a grid
We will use BFS from the top-left cell towards bottom-right cell. If we reach the bottom-right cell, then we return True
. Otherwise, we return False
.
Time complexity:...
January 4, 2023
Check if number is a sum of powers of three
We will divide the number by 3 until it becomes 0. If the remainder is 1, then we add 1 to the result. Otherwise, we add 0 to the result.
Time complexity: O(log(n))
Space complexity:...
January 3, 2023
Finding the number of visible mountains
We will use a monotonic stack to keep track of the mountains that are visible. We will iterate over the mountains and for each mountain we will pop the stack until the top of the stack is smaller...
ReadJanuary 3, 2023
Delete columns to make sorted
We will iterate over the columns and for each column we will check if the column is sorted. If it is not, we will increment the number of columns to delete. Finally, we will return the number of...
ReadJanuary 2, 2023
Divide intervals into minimum number of groups
We will sort the intervals by the end point. Then we will iterate over the intervals and for each interval we will check if the start point is greater than the end point of the last interval in the...
ReadJanuary 2, 2023
Car pooling
We will sort the trips by the starting point. Then we will iterate over the trips and for each trip we will add the number of passengers to the current number of passengers. If the current number of...
ReadJanuary 2, 2023
K highest ranked items within a price range
We will use a heap to store the top k
items. We will iterate over the items and for each item we will check if the price is within the price range. If it is, we will check if the heap...
January 1, 2023
Two sum bsts
We will traverse the tree and store the values in a set. Then we will iterate over the set and check if target - num
is in the set.
Time complexity: O(n)
Space...