Problems
November 26, 2022
Design browser history
We can use a doubly linked list to store the history. We can use a pointer to point to the current node. We can use visit
to add a new node to the end of the list. We can use...
November 26, 2022
Strobogrammatic number
We will use a lookup table to store the pairs. We will iterate over the string. If the character is not in the lookup table, we will return false. If the character is in the lookup table, we will...
ReadNovember 26, 2022
Minimize maximum pair sum in array
We will sort the array. We will iterate over the array from the beginning and the end. We will add the first element and the last element to the result. We will return the result. Time complexity:...
ReadNovember 26, 2022
Check if word is valid after substitutions
We will use a stack to store the characters. We will iterate over the string. If the character is a
, we will push it to the stack. If the character is b
, we will check if...
November 26, 2022
Maximum number of coins you can get
We will use a double ended queue to store the piles. We will sort the piles in descending order. We will iterate over the piles. We will pop the first and the last element from the queue. We will add...
ReadNovember 26, 2022
Maximum twin sum of a linked list
We will find the middle of the linked list. Then we will reverse the second half of the linked list. Then we will iterate over the first half and the second half of the linked list to find the...
ReadNovember 26, 2022
Spiral matrix IV
The idea to take from this, is how to rotate the direction in a concise way. Initially we start by adding 1 to the column, and 0 to the row (going right) If we hit a wall/edge, we must swap the...
ReadNovember 26, 2022
Find smallest common element in all rows
We will flatten the matrix into a single array. Then count all the elements in the array. We will get the number that appears the most in the array. If the frequency of the number is equal to the...
ReadNovember 26, 2022
Next greater node in linked list
We can use a stack to store the nodes. We will iterate over the list from the end to the beginning. We will pop the nodes from the stack until the top node is greater than the current node. We will...
ReadNovember 26, 2022
Meeting rooms III
Ready contains the ready room index for meetings. Rooms contains the rooms in use with [end_time, room_index] as element. For [start, end] in the sorted meetings, we firstly release the rooms that...
Read