BST Traversal with Edge Cases (Skewed Tree, Negative Values)
viaLeetCode
Problem: A standard BST traversal problem (e.g. in-order traversal or a BST-validity/search style question), with the interviewer walking through several edge cases: a skewed tree (essentially a linked list), and negative node values.
Approach: Implement traversal recursively or iteratively (using an explicit stack to simulate recursion), ensuring the same logic correctly handles a completely skewed tree (recursion depth O(n) in the worst case — discuss stack overflow risk and how an iterative approach avoids it) and negative values (ensure comparisons don't assume non-negative values, e.g. avoid using 0 or -1 as sentinel "no value" markers).
asked …