Problems


September 8, 2022

Build an array with stack operations

We will create a stack to match with our target and also create a result list. Then we start a loop from 1 to n and append each number to the stack. If the top of the stack does not match our target,...

Read

September 8, 2022

Robot bounded in circle

The idea is, after the first iteration, if the direction is not north facing or the current position is the start position, then it is a cycle, otherwise not. First if condition basically encounters...

Read

September 8, 2022

Minimum consecutive cards to pick up

We will use a set to keep track of cards in the hand. Initially we will assume the current number of cards in the hand in infinity. We will have 2 pointers, we will move our right pointer, check if...

Read

September 8, 2022

Repeated dna sequences

We will use a sliding window which is 10 characters long. For each window, we will add this to a lookup set. If the window is already present in the lookup set, that means we already have it more...

Read

September 8, 2022

Combination sum III

We will run DFS towards our decision tree, for building a decision tree, we have 2 options, either we take the number or we skip the number. We will check when the sum of the numbers we took is equal...

Read

September 7, 2022

Keys and rooms

We will create a set with all the nodes. First we put them in unvisited set. Then we start traversing the graph using BFS and remove nodes from unvisited set after every node visit. Finally when the...

Read

September 7, 2022

Print binary tree

First we will calculate the height of the tree. Our result will be a 2d matrix where the each row will have 2^height-1 element and there will be height rows in total. We...

Read

September 7, 2022

Construct string from binary tree

We will use recursive DFS to traverse the tree and append the result to a string and return it. Time Complexity: O(n) Space Complexity: O(n)

Read

September 6, 2022

Implement magic dictionary

We will use the Trie data structure to store all the elements in the dictionary. Building the dictionary is pretty strait forward, we will insert all the words from the dictionary to the trie. As we...

Read

September 6, 2022

H-index II

We will seach for the highest mid where the value of mid is greater that or equal to the numbers of elements on the right from that mid index. Time Complexity: O(log(n)) Space...

Read
... 60 61 62 63 64 ...