• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
August 21, 2024 |10 Views

PROBLEM OF THE DAY : 25/07/2024 | Array to BST

Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Devashish Khare. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Binary Search Tree but also build up problem-solving skills.

Given a sorted array. Convert it into a Height Balanced Binary Search Tree (BST). Return the root of the BST.

Height-balanced BST means a binary tree in which the depth of the left subtree and the right subtree of every node never differ by more than 1.

Note: The driver code will check the BST, if it is a Height-balanced BST, the output will be true otherwise the output will be false.

Examples :

Input: nums = [1, 2, 3, 4]
Output: true
Explanation: The preorder traversal of the following BST formed is [2, 1, 3, 4]:            
                   2         
                 /   \        
               1     3                
                        \                 
                         4

Problem Link: https://practice.geeksforgeeks.org/problems/array-to-bst4443/1