Problems


May 12, 2023

Android unlock patterns

We can use backtracking to solve the problem. We will start from the first number and try to find all possible patterns. We will use a hashmap to store the numbers that are already used. Now we will...

Read

May 11, 2023

Solving questions with brainpower

We will start from index 0, then either take the current element or skip it. If we take the current element, we will move forward to the next element. If we skip the current element, we will move...

Read

May 11, 2023

Maximum length of subarray with positive product

We can use top-down dynamic programming to solve the problem. We will start from index 0, and move forward. If the current element is positive, we will increment the result by 1 and move forward. If...

Read

May 10, 2023

Uncrossed lines

We can use top-down dynamic programming to solve the problem. We will use two pointers i and j to iterate over A and B respectively. If A[i] ==...

Read

May 10, 2023

Equal tree partition

Cutting an edge means cutting off a proper subtree (i.e., a subtree but not the whole tree). I collect the sums of these proper subtrees in a set and check whether half the total tree sum is a...

Read

May 10, 2023

Largest unique number

We will use a hashmap to store the frequency of each number. Then we will iterate over the hashmap and return the maximum number whose frequency is 1. If there is no such number, we will return -1....

Read

May 9, 2023

Increasing order search tree

We can just do an inorder traversal and keep track of the previous node. Then we will set the left child of the current node to None and the right child to the previous node. Finally, we...

Read

May 8, 2023

Prime in diagonal

We will start our initial result with 0. Then we will iterate over the matrix and check if the current diagonal element is a prime number. If it is, we will keep the maximum between current result...

Read

May 8, 2023

Valid boomerang

We will calculate the slope of the line between the first and second point and the slope of the line between the first and third point. If the slope of the first and second point is the same as the...

Read

May 7, 2023

Matrix diagonal sum

We will traverse the matrix row by row. For each row, we have to take 2 diagonal position and add it to the result. If the matrix has an odd number of rows, we have to subtract the middle element...

Read
... 3 4 5 6 7 ...