Problems


August 20, 2022

Number of pairs of strings with concatenation equal to target

First we will count the number of frequency of each elements of the input. Then iterate over all possible slices of target and multiply by the count and add it to our final result. If some slices are...

Read

August 20, 2022

The k weakest rows in a matrix

First we iterate through the whole matrix to count the number of 1's in the matrix and put it in an min heap. Then we extract top k elements from that heap. Time Complexity:...

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

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