Validate That a Price Index Tree Obeys Search Tree Ordering
Last updated: November 29, 2026
Quick Overview
A pricing service stores product prices in what is supposed to be a binary search tree with strictly increasing inorder values. Return True if the tree really is a valid BST.
Amazon
November 29, 20260
0
0 solved
A pricing service stores product prices in what is supposed to be a binary search tree with strictly increasing inorder values. Return True if the tree really is a valid BST.
A quick Amazon online assessment item checking that you know the BST property is global, not just parent versus child. A corrupted price index silently returns wrong range queries, which is the framing interviewers like to give it.
What the Interviewer Expects
- Explain why checking each node against only its children is insufficient
- Pass down lower and upper bounds, or compare with the previous inorder value
- Clarify whether duplicates are allowed
- Use an iterative inorder walk to avoid recursion limits
- State O(n) time and O(h) space
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you allow duplicates on the left subtree only?
- How would you find the first node that violates the ordering?
- Can you validate in O(1) extra space with Morris traversal?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: root of a binary tree (possibly empty). Output: True when an inorder traversal yields strictly increasing values, which is equivalent to every node lying strictly between the bounds implied by ...
High-Level Design
An inorder traversal of a valid BST is sorted. Walk the tree inorder with an explicit stack and keep the previous value; if the current value is not greater than the previous one, fail. This avoids th...