Problems


August 7, 2022

Non overlapping intervals

First we will sort the intervals. Then we will iterate through all the intervals, compare if we have any collision between 2 consecutive interval, if yes, then we will count that, then after the...

Read

August 7, 2022

Minimum interval to include each query

We will keep track of the smallest interval for each query in a min heap, so whenever we pop something from the heap, it's always the smallest number. And then we put that smallest number in our...

Read

August 7, 2022

Detect squares

We will keep track of each elements in a list and their respective points count in a hashmap. Whenever we add a point, we increment the points count and also add the point in points list. We we...

Read

August 7, 2022

Rotate image

We will save the topleft to a temporary variable and then move the bottom left to top left, then move the bottom right to bottom left and move the top right to bottom right and then finally move the...

Read

August 7, 2022

Set matrix zeroes

First we will go through the whole matrix, if we find a zero and we append it's row position to a rows to zero list and column position to columns to zero list. Then We go through each row from rows...

Read

August 7, 2022

Spiral matrix

First we will determine the value of left, right, top and bottom. Then we append the top row to our result, then right column, then bottom row in reverse order and then left column in reverse order....

Read

August 7, 2022

Find median from data stream

We will use a min heap and a max heap to calculate the median. The small heap will be a max heap and large heap will be a min heap. All the elements of the small heap will be smaller than large heap....

Read

August 6, 2022

Serialize and deserialize binary tree

For serialize the tree, we will traverse the tree in preorder and whenever we hit a null node, we put a # character there. Then we join each character with a comma delimeter and return...

Read

August 6, 2022

Merge k sorted lists

We can merge 2 sorted list with O(n) time complexity. Now we can go through the lists, and merge it one by one, this will be a O(n^2) operation. But if we merge every 2 list...

Read

August 6, 2022

Reverse nodes in k group

We will create a helper funtion to get the kths item of the list. Then as we go through the whole list, we will take kth item, reverse it in place and move forward till the end of the ;list. Time...

Read
... 78 79 80 81 82 ...