Challenge: Is It a BST Array?
Let’s check if an array is also a pre-order traversal of a BST.
We'll cover the following
Problem
Given an array of integers, find if it represents a pre-order traversal of a BST.
Input
An integer array.
Output
Return true
if the array is the pre-order traversal of a BST, otherwise false
.
Sample input
array = {5, 2, 4, 6, 9, 10}
Sample output
true
Let’s look at the illustration below to better understand the problem.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.