Problems


December 19, 2022

Binary tree longest consecutive sequence

We will use a recursive function to find the longest consecutive sequence in the left subtree and the right subtree. Then we will compare the longest consecutive sequence in the left subtree and the...

Read

December 18, 2022

Day of the year

We can use the datetime module to convert the date to a datetime object and then use the timetuple method to get the day of the year. Time complexity: O(1)...

Read

December 18, 2022

Pancake sorting

We will iterate through the array, and for each element, we will find the index of the element in the array. Then we will reverse the array from the index of the element to the end of the array. Then...

Read

December 18, 2022

Powerful integers

We can use brute force to calculate all the possible values of x^i + y^j until the value is less than the bound and store them in a set. Then we can return the set as a list. Time...

Read

December 18, 2022

Check if there is a valid parentheses string path

We will use top-down memoization to solve the problem. For every opening parenthesis we add 1 to our current and for every closing parenthesis we subtract 1 from our current. If we ever reach a...

Read

December 17, 2022

Minimum rounds to complete all tasks

We will count the different tasks and calculate the number of rounds for each task. Then we will return the maximum number of rounds. Time complexity: O(n) Space complexity:...

Read

December 17, 2022

Number of boomerangs

We will use a hashmap to store the distance between each point and the current point. Then we will iterate through the hashmap to calculate the number of boomerangs. Time complexity:...

Read

December 17, 2022

Maximum sum score of array

We will calculate the prefix sum of the array. Then we will iterate through the array, and for each element, we will find the maximum sum of the subarray that ends at the current element. Then we...

Read

December 17, 2022

Ternary expression parser

We will use a stack to evaluate the expression. We start from the end of the expression, then append the value to the stack. If the number of element in the stack is more than 2, and the second last...

Read

December 17, 2022

Add two integers

This is a stupid problem. We can just add to numbers and return the result. Time complexity: O(1) Space complexity: O(1)

Read
... 16 17 18 19 20 ...