# Problems

May 12, 2023

## Find permutation

Loop on the input and insert a decreasing numbers when see a 'I'. Or insert a decreasing numbers to complete the result.
Time complexity: `O(n)`

Space complexity: `O(1)`

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

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

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

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

##
Sort array by increasing frequency

We will use a hashmap to store the frequency of each number. Then we will sort the array by the frequency of each number. If the frequency of two numbers is the same, we will sort them by the value...

Read