Skip to content

[FEATURE] Construct Binary Search Tree from Preorder Traversal #2246

@Amisha2093

Description

@Amisha2093

Detailed description

Construct Binary Search Tree from Preorder Traversal.

Problem Statement:
Given an array of integers preorder, which represents the preorder traversal of a BST (i.e., binary search tree), construct the tree and return its root.

Test Case:
Input: preorder = [8,5,1,7,10,12]
Output: [8,5,10,1,7,null,12]

Context

This is a very famous and standard problem asked in most of the interviews. This will enhance the logical thinking of the programmer.

Possible implementation

A binary search tree is a binary tree where for every node, any descendant of Node.left has a value strictly less than Node.val, and any descendant of Node.right has a value strictly greater than Node.val.

A preorder traversal of a binary tree displays the value of the node first, then traverses Node.left, then traverses Node.right.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requeststaleAuthor has not responded to the comments for over 2 weeks

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions