Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Think of using the stack data structure.
Put the first node in the stack.
Iterate over the array and check if the node at the top of the stack is its parent; if it’s not, then pop the last element of the stack and check until you reach the parent of the current node in the array.
If the stack gets empty at any point, then the array is not the preorder.