Problems


September 6, 2022

Merge nodes in between zeros

We will create a dummy node for our result. Then we will start from the head, sum the values of the nodes until we reach another 0, then attach a node to our result list. We will repeat it until we...

Read

September 6, 2022

Query kth smallest trimmed number

We will take the nums, iterate over each query, and take the last trim values of the nums and store it as integer in a values array along with the index. Then we sort this values array and take the...

Read

September 6, 2022

Seat reservation manager

We will create a min heap with the capacity of the seat manager. Then when someone reserve a seat, we will pop it from our min heap, and when someone unreserve a seat, we will push back the value to...

Read

September 6, 2022

Sort an array

We will use divide and conquar to solve this sorting porblem. We will be using classic merge sort. Time Complexity: O(nlog(n)) Space Complexity: O(nlog(n))

Read

September 5, 2022

Path sum II

We will use DFS along with backtracking to get the paths of every root to leaf path that adds upto the target. Time Complexity: O(n) Space Complexity: O(n), for...

Read

September 5, 2022

Sort list

We will use standard merge sort to sort the list, to get the middle node, we will use a fast and slow pointer approach, rest is standard merge sort stuffs. Time Complexity: O(nlog(n))...

Read

September 5, 2022

Count primes

We will use the algorithm Sieve of Eratosthenes to find the number of primes within a range. Time Complexity: O(nlog(log(n))) Space Complexity: O(n)

Read

September 5, 2022

Restore ip addresses

We will create a decision tree based on the rule that each segment of the ip address can be between 0 and 255. Then we run our DFS to get all possible options and return the result. Time...

Read

September 5, 2022

Basic calculator II

We will take a stack. Initially our operation and operand will be 0 and + append each character to the stack. If the character is numeric, until we reach an operand we will calculate the...

Read

September 5, 2022

Number of enclaves

We will run DFS from every bordering position of the grid and turn the 1's to 0's. Then we will just count the number of position where we still have 1's left, and return that count as result....

Read
... 62 63 64 65 66 ...