Reported September 2026
Charta Healthbinary search

Inorder Successor in a Binary Search Tree

Reported by candidates from Charta Health's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Charta Health OA. Under 2s to a working solution.
Founder's read

Charta Health reported this one in September 2026, and it looks friendlier than it is. Inorder successor in a BST sounds like a traversal problem, but it really reduces to one walk down the tree, the same move a binary search makes. No parent pointers, up to 100000 nodes, so a skewed tree can wreck a sloppy recursive approach. If you've got the OA in a day or two, this is a pattern problem, not a hard one. Know the trick and it takes ten lines. StealthCoder sits invisibly on your screen as a safety net if your mind goes blank mid-assessment.

The problem

You are given the root root of a non-empty binary search tree and an integer targetValue that appears in the tree.
Return the value of the node immediately after the target in an inorder traversal. An inorder traversal visits the left subtree, then the node, then the right subtree. If the target is the largest value and has no inorder successor, return -1.
The tree has no parent pointers and all node values are distinct.

Function
findInorderSuccessor(root: TreeNode, targetValue: int) → int

Examples
Example 1
root = [20,10,30,5,15,25,35]
targetValue = 15
return = 20
The inorder sequence is [5,10,15,20,25,30,35], so 20 follows 15.
Example 2
root = [20,10,30,5,15,25,35,2,7,13,17]
targetValue = 10
return = 13
The target has a right subtree. Its successor is the leftmost value in that subtree, 13.
Example 3
root = [2,1,3]
targetValue = 3
return = -1
The largest value is last in inorder order, so it has no successor.

Constraints
The tree contains between 1 and 100000 nodes.
0 <= Node.val <= 1000000000.
All node values are distinct, and the tree satisfies the binary-search-tree ordering invariant.
targetValue equals the value of exactly one node.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Here's the trick. Start at the root and keep a variable called successor, initially -1. At each node, if its value is greater than the target, that node is a candidate successor, so save it and go left. Otherwise go right. When you land on the target, you don't stop. You keep walking, because the answer is either the leftmost node of its right subtree or the last ancestor where you turned left. This single loop handles both cases without parent pointers. The common pitfall is writing a full inorder traversal, which costs O(n) time and risks stack overflow on a degenerate tree with 100000 nodes. Another is forgetting the no-successor case for the maximum value. Iterative search runs in O(h) time and O(1) space. If you freeze during the live OA, StealthCoder can surface this loop while you type it out.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Inorder Successor in a Binary Search Tree cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as inorder successor in bst. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Charta Health's OA.

Charta Health reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Inorder Successor in a Binary Search Tree FAQ

What's the trick for the Charta Health inorder successor question?+

Walk down from the root like a binary search. When the current value is greater than the target, record it as the candidate and go left. Otherwise go right. The last recorded candidate is the answer, or -1 if none was recorded.

How hard is this problem really?+

Easy to medium. The logic is short, but candidates overthink it and write a full traversal. If you see it as a search for the smallest value greater than the target, it's about ten lines of code.

Do I need to handle the case where the target has a right subtree separately?+

No. The single loop covers it. When you hit the target, you go right, then keep going left whenever a node exceeds the target. That ends at the leftmost node of the right subtree, which is the successor, as in Example 2.

What time and space complexity should I aim for?+

O(h) time, where h is tree height, and O(1) space with the iterative loop. Worst case on a skewed tree is O(n) time. Avoid recursion here, since 100000 nodes in a chain could overflow the call stack.

How do I prep for this in 48 hours?+

Practice writing the iterative loop from memory on the three given examples, including the largest-value case returning -1. Then try the mirror version, inorder predecessor. If you can do both without a traversal, you're ready.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Charta Health.

OA at Charta Health?
Invisible during screen share
Get it