Problems


August 20, 2022

Minimum number of refueling stops

We can be greedy and use a max heap to to count the number of refueling stop. First we will append the target to the stations list, where fuel will be 0. We will assing the startFuel as nextStop as...

Read

August 19, 2022

Design parking system

We will create a hashmap, with the capacity. Each time, we add a car, we decrease the capacity by 1. If the capacity is already filled up, we return false, otherwise return true. Time Complexity:...

Read

August 19, 2022

Split array into consecutive subsequences

First we will count all the numbers. Then we will create a second hashmap to keep track of subsequences. Then we iterate over the input array, then if there is already a subsequence in place, we add...

Read

August 18, 2022

Reduce array size to the half

We will count the values, then sort them. Then we start removing item from the most common elements and count them. When the removed elements reach more than half of the input array, we return the...

Read

August 18, 2022

Strange printer

If we start from the last character, then it will always print with 1 switch. This will be our base case. We will run DFS to the rest of the characters. Then we will look through each elements until...

Read

August 17, 2022

Beautiful arrangement

Generate the array of numbers that will be used to create permutations of 1 to n (n inclusive) ex: 3 will become [1, 2, 3]. Then, iterate through all elements in the list and compare it to i which is...

Read

August 17, 2022

Unique morse code words

We will translate each word to a morse code and then add that to a set. Finally return the number of elements of that set. Time Complexity: O(n*m), n is the number of words, m is...

Read

August 16, 2022

String to integer atoi

First we will strip any whitespace characters, and then check if the length is zero, we immediately return 0. Then we check the sign, if the sign is + or -, we keep that in...

Read

August 16, 2022

Find triangular sum of an array

This problem is basically reverse pascal's triangle. For the ith element of one level, we can calculate it from the i and i+1 th element from the previous level and mod the result by 10. After each...

Read

August 16, 2022

First unique character in a string

First we will count each character of the string. Then we iterate from the beginning, check which character has character count 1, return that. If we can't find anything with character count 1, we...

Read
... 73 74 75 76 77 ...