Problems


October 13, 2022

Shift 2d grid

We are given a 2d grid of size m x n and an integer k. We need to shift the grid k times. In one shift operation, we shift the grid by one cell to the right....

Read

October 12, 2022

Determine whether matrix can be obtained by rotation

We will rotate the matrix 4 times and check if it is equal to the target matrix. Time complexity: O(n^2) Space complexity: O(n^2)

Read

October 12, 2022

Largest perimeter triangle

We will sort the array in descending order and check if the sum of the first three numbers is greater than the sum of the next three numbers. If it is, we return the sum of the first three numbers....

Read

October 11, 2022

Increasing triplet subsequence

We will keep track of the smallest and second smallest number in the array. If we find a number that is greater than both, we return true. Otherwise, we return false. Time Complexity:...

Read

October 11, 2022

Number of recent calls

We will use a queue to store the recent calls. We will remove the calls that are not in the range of 3000ms. Then we will return the size of the queue. Time complexity: O(n) Space complexity: O(n)

Read

October 10, 2022

Break a palindrome

We can check the half of the string and if a character is not a, we can replace it with a. If all characters are a, we can replace the last character with b. If the string is a single character, we...

Read

October 9, 2022

Convert bst to greater tree

We will iterate over the tree in reverse inorder and keep track of the sum of all the nodes we have traversed so far. We will add the sum to the current node and update the sum with the current node...

Read

October 9, 2022

Find bottom left tree value

We will traverse the tree with BFS and assign the first node of the each level in our result. At the end of the traversal, we will return the result, which will store the left most value of the last...

Read

October 9, 2022

Flip equivalent binary trees

We will start traversing both tree with DFS and check whether the left subtree and right subtree are equal for both tree or left subtree is equal to right subtree and vice-versa both tree. Time...

Read

October 9, 2022

Frequency of the most frequent element

First we will sort the array. Then it turns into a sliding window problem, the key is to find out the valid condition k + sum >= size * max. For every new element nums[r] to the sliding window, add...

Read
... 49 50 51 52 53 ...