Challenge: Is It a BST Array?

Let’s check if an array is also a pre-order traversal of a BST.


Given an array of integers, find if it represents a pre-order traversal of a BST.


An integer array.


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


Let’s look at the illustration below to better understand the problem.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.