Company: Mathworks_29july
Difficulty: medium
Check the Structure Problem Description Given a pre-order traversal sequence of a binary tree, determine if it represents a Binary Search Tree (BST). A binary tree consists of nodes, each having up to two child nodes and a value. A BST must satisfy two conditions: The left subtree of a node contains only values less than the node's value. The right subtree of a node contains only values greater than the node's value. Pre-order traversal visits the root node first, then recursively visits the left subtree, followed by the right subtree. Here's the pseudocode for pre-order traversal: If the root is null, return an empty list. For a non-null root node: Create a pre-order traversal list for the left subtree. Create a pre-order traversal list for the right subtree. Return the concatenated list: node + left subtree + right subtree. Given a pre-order traversal sequence, check if it can represent a valid BST. Return "YES" if it can, or "NO" if it cannot. Examples Example 1: Input: nodes = [2,