Problems


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

Multiply strings

We will first reverse both string and then calculate the first characters of both string, to get the digit. Then we store this digit at (i1+i2) position of our result. The (i1+i2+1) position will...

Read

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

Pow(x, n)

We will follow divide and conquar method to solve the problems. We we divide the n until it's a single digit, then the muliplication result is the number itself. When we merge it, we will join the...

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 6, 2022

Binary tree maximum path sum

We will calculate the sum of left subtree and right subtree and return the value of maximum of them added with the current node value from our recursive DFS method. In the process we will keep track...

Read

August 6, 2022

Design twitter

This is a classic object oriented design problem. We will use a hashmap for the tweet map and another hashmap for the follow map. Each element of the tweet map with be a list, and each element of the...

Read

August 6, 2022

Kth smallest element in a bst

If we traverse the binary search tree in inorder, then we will actually get the sorted array. Then we can easily pick the kth element by picking k-1 indexed value from the array, as it's mentioned, k...

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