Problems


November 21, 2022

Base 7

We will divide the number by 7 and keep track of the remainder. We will add the remainder to the result and multiply the result by 10. We will repeat this process until the number is 0. Time...

Read

November 21, 2022

Vowel spellchecker

We will use a set to store the words in the wordlist. Then, we will use a dictionary to store the words in the wordlist with the vowels replaced with *. Then, we will iterate through the...

Read

November 21, 2022

design linked list

We will use a stack to store the values and then do the operations on the stack.

Read

November 21, 2022

Total cost to hire k workers

We will sort the workers by their quality and iterate through them. For each worker, we will add their wage to the heap and remove the highest wage if the heap size is greater than k. We...

Read

November 21, 2022

Sum of absolute differences in a sorted array

The absolute difference between two numbers a and b is: a - b: When a is greater than or equal to b. b - a: When a is less than or equal to b. These cases overlap when a...

Read

November 20, 2022

Number of orders in the backlog

We will use two heaps to keep track of the buy and sell orders. The buy orders will be stored in a max heap and the sell orders will be stored in a min heap. We will also keep track of the total...

Read

November 20, 2022

Find all duplicates in an array

We will count the frequency of each number in the array, and return the numbers that appear twice. Time complexity: O(n) Space complexity: O(n)

Read

November 20, 2022

Widest vertical area between two points containing no points

We sort the points by x-coordinate, and find the maximum distance between two consecutive points. Time complexity: O(nlogn) Space complexity: O(n)

Read

November 20, 2022

Shopping offers

We can use DFS with memoization to solve this problem. We will keep track of the current state of the shopping list. Then we will iterate over each offer and we will check if the offer is valid. If...

Read

November 20, 2022

Reverse prefix of word

We will iterate through the word and check if the current character is equal to the first character of the prefix. If it is, we will reverse the prefix and return the word. Time complexity:...

Read
... 33 34 35 36 37 ...