Problems
November 1, 2022
Letter tile possibilities
We will use DFS to generate all possible strings. We will generate all the strings, put it in a set for remove duplication and finally return the count as the result. Time complexity:...
ReadMay 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...
ReadMay 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...
ReadMay 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...
ReadMay 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....
ReadMay 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] ==...
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...
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...
ReadMay 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...
ReadMay 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