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...
ReadAugust 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...
ReadAugust 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....
ReadAugust 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...
ReadAugust 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....
ReadAugust 7, 2022
Count vowels permutation
We are going through the decision tree to map out all the possible combinations. The calculation will be kept in a 2-dimentional array, where each index will represent the combination of the string...
ReadAugust 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...
ReadAugust 6, 2022
Validate binary search tree
We will run a DFS, and each iteration we will compare the value of the node with a left and right value, which we will pass along each iteration. For root, this values will be negative and positive...
ReadAugust 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...
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