6.Construct Binary Search Tree from Preorder Traversal

Example:
Input: [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]
Solution Tree

Iterative Solution:-

  • Searching the position and then inserting

Time Complexity: O(n^2) or O(n log(n))

Optimized Solution using stack

Time Complexity: O(n)

Last updated

Was this helpful?