Logic behind the problem


#1

preorder traversal is:root left right so for every element in array which is greater than it’s predecessor it has to be greater than all it’s predecessor in the array. use stack