Leetcode Problem 1300-1399
Most intuitive Solution
- Traversal with any order and get all the nodes of the BST and then sort them.
By inorder traversal and merge sort
- We know that inorder traversal of BST gives us the sorted list.
- Then we can merge these two lists into one using merge technique similar to merge sort.
using reverse function
Checking if string is palindrome
O(N^2) Time solution
- Brute force for each array element.
O(N) Time O(N) space optimization
- Store the count in a bucket and take the running sum.
DFS
- Simple dfs traversal.
- check if original node is null if yes then return null.
- if original node is equal to target node then return the cloned node.
- else recur ot left and right of the original and cloned subtrees and store the result in the left and right.
- if left is not null return left else return right.
O(N^2) Time solution
O(N*logN) based on βsmaller elements after selfβ.
- It is HARD level problem
- Will be added soonβ¦
DP Solution