Find the Next Higher Price Tier Using a BST Successor
Last updated: November 29, 2026
Quick Overview
Subscription price tiers live in a binary search tree. Given a tier node, return the node holding the next larger price (its inorder successor), or None if it is the largest. Nodes have no parent pointers.
Amazon
November 29, 20260
0
0 solved
Subscription price tiers live in a binary search tree. Given a tier node, return the node holding the next larger price (its inorder successor), or None if it is the largest. Nodes have no parent pointers.
A technical screen question in the Amazon style that checks you can reason about inorder order without materializing the whole list. It maps to upsell logic that suggests the next tier above a shopper's current plan.
What the Interviewer Expects
- Handle the case where the node has a right subtree: the leftmost node there
- Otherwise descend from the root, remembering the last node where you went left
- Avoid building the full inorder list
- Explain O(h) time and O(1) space
- Discuss how parent pointers would change the approach
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 find the inorder predecessor instead?
- What if nodes had parent pointers but you did not have the root?
- How would you build an iterator that yields successors one at a time in amortized O(1)?
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: BST root and a node p in the tree (unique values). Output: the node with the smallest value greater than p.val, or None....
High-Level Design
Search from the root comparing against p.val. Whenever p.val is less than the current node's value, that node is a candidate successor, so record it and go left to look for a smaller candidate. Otherw...