Problems
July 22, 2022
Partition list
We will have 2 separate linked list, left and right. All the values that is less than target will go to the left list, all the values that is greater than or equal to target will go to the right...
ReadJuly 21, 2022
Meeting rooms
We will sort the given array based on start time. Then we can compare, if the end of first meeting is before the start of last meeting, if yes return False, else return True. Time Complexity:...
ReadJuly 21, 2022
Implement stack using queues
It's easy to implement a stack using queue. You can pop, peek and check the empty as you normally do in a queue. You just need to do some extra work during the push method. First you push it to the...
ReadJuly 21, 2022
Implement trie prefix tree
This problem literary ask to implement a prefix tree or Trie. Each node will have children for which we have used a hashmap for constant time insert and lookup abd a boolean value to denote whether...
ReadJuly 21, 2022
Graph valid tree
First we create a adjacency list from the edge list. Then we traverse the whole graph starting from node 0. If we don't have any cycle or any disjoint node, then it's a valid tree, otherwise we...
ReadJuly 21, 2022
Merge intervals
First we sort the intervals with the start key. Then we append the first item on the output list. Then we will iterate over all intervals and compare the last end with the current start, if the last...
ReadJuly 21, 2022
Maximum subarray
We will have 2 running count, one is for our result and one is for the total of the array. First we assume first element of the input is out result. Then we iterate through the input and calculate...
ReadJuly 21, 2022
Fibonacci number
This is the classing fibonacci number problem. First we solve this using recursion, then we memoize it to increase efficiency.
Time Complexity: O(n)
Space Complexity:...
July 20, 2022
N-ary tree preorder traversal
We will traverse the tree with recursive DFS, as it is preorder traversal, we first append the root to our result and then traverse all the children.
Time Complexity: O(n)
Space...
July 20, 2022
Binary tree preorder traversal
We will traverse the tree with recursive DFS, as it is preorder traversal, we first append the root, then the left subtree and then right subtree.
Time Complexity: O(n)
Space...