Problems


October 13, 2022

Find positive integer solution for a given equation

Given a function f(x, y) and a value z, return all positive integer pairs x and y where f(x,y) == z. Rephrase the problem...

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

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

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

Two sum IV input is a bst

This is very similar to two sum problem. But rather than traversing an array, we will traverse a tree. We will be using DFS to traverse the tree and along with the way, we will store the difference...

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