Problems


October 25, 2022

Escape the ghosts

We will calculate the Manhattan distance between the ghost and the target. If the ghost is closer to the target than the player, we will return False. Otherwise, we will return...

Read

October 25, 2022

Serialize and deserialize bst

we will use preorder traversal to serialize the tree. Then we will use the preorder traversal to deserialize the tree as well. Time Complexity: O(n) Space Complexity:...

Read

October 25, 2022

Reverse odd levels of binary tree

we will use preorder traversal to reverse the odd levels of the tree. Time complexity: O(n), where n is the number of nodes in the tree. Space complexity: O(h) where h is the height of the tree

Read

October 25, 2022

Check if two string arrays are equivalent

We will join the two arrays to strings and check if they are equal. Time Complexity: O(n) Space Complexity: O(n)

Read

October 24, 2022

Open the lock

We will use a queue to store the current state of the lock. Then we will iterate over the queue and check if the current state is the target state. If not, we will iterate over each digit and check...

Read

October 24, 2022

Maximum length of a concatenated string with unique characters

We will use a set to filter out the strings with duplicate characters. Then we iterate over each sting and check if it has duplicate characters. If not, we will add it to the set. Then we will...

Read

October 23, 2022

Set mismatch

The sum of all numbers in the array is n*(n+1)/2. We calculate all the numbers in the array and subtract it from the sum. The result is the missing number. We will subtract the sum of...

Read

October 23, 2022

Can place flowers

We will assume the first and last position are not occupied, so we will imagine 2 empty position at both boundary. Then we will iterate the array and check if the current position is empty and the...

Read

October 23, 2022

Integer break

We will use dynamic programming to solve this problem. We will create an array dp with size n+1. dp[i] will store the maximum product we can get by breaking...

Read

October 22, 2022

Minimum number of operations to convert time

We will convert the time to minutes. Then we will calculate the difference between the target time and the current time. If the difference is negative, we will add 24 hours to it. Then we will...

Read
... 46 47 48 49 50 ...