Problems


September 5, 2022

Longest absolute file path

Use stack to represent structure of a directory where the root of a directory is at index 0. Directory level can be infer from the number of tabs. ie "" is level 0, "\n" is level 1 and so on. Start...

Read

September 5, 2022

Remove duplicate letters

We will create a hashmap to keep track of last occurance of the letters. Then we will have a visited hashset and a stack to keep track of the letters. We traverse sequentially on the string, for each...

Read

September 4, 2022

Populating next right pointers in each node II

We will traverse the tree with BFS and in each level, we will append the nodes to a list. After each level traversal, we take these nodes, and assing the next node to it's right node. We will repeat...

Read

September 4, 2022

Construct binary tree from inorder and postorder traversal

We know, the last index of postorder traversal is always the root of the tree, from that info, we can find the root in inorder traversal too. From there, we will find the left inorder subtree and...

Read

September 4, 2022

Recover binary search tree

We will traverse the tree with inorder traversal and add each nodes to the a list. Then we sort the values of each nodes, then iterate over the sorted values, and assign the values to respective tree...

Read

September 4, 2022

Unique binary search trees

We will take the top-down approach to solve the problem. We will start from 1 and for every position, we take is as root, and build a tree with the left and right subarray for that root position, and...

Read

September 4, 2022

Binary tree zigzag level order traversal

We will traverse the tree with BFS and append the values of each level to our result list. And for each alternative level we change the order. Finally return the result after we visit each node....

Read

September 4, 2022

Binary tree level order traversal II

This is a classing BFS problem. We should traverse the whole tree with BFS, and store the values level by level to a list. Then combine each level to a list and return the reversed list as result....

Read

September 4, 2022

Binary search tree iterator

We will create a queue to store our values while create the oterator class. Then for next, we will pop the values from the queue and return, for hasNext, we will check it the queue is empty or not....

Read

September 4, 2022

delete-node-in-a-bst

We will check whether the key is greater than root, then the key is in right subtree, if the key is less than root, then key is in left subtree. If the key is the root, then we check, if there is a...

Read
... 64 65 66 67 68 ...