Problems


January 5, 2023

Number of segments in a string

We will split the string by space, then count the number of non-empty string. Time complexity: O(n) Space complexity: O(n)

Read

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

Read

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

Read

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

Read

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

Read

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

Read

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

Read

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

Read

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

Read

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

Read
... 9 10 11 12 13 ...