MEDIUMasked at 12 companies

Unique Binary Search Trees

A medium-tier problem at 62% community acceptance, tagged with Math, Dynamic Programming, Tree. Reported in interviews at Tower Research Capital and 11 others.

Founder's read

Unique Binary Search Trees is a medium-difficulty problem that combines dynamic programming with tree theory, and it's been asked by Amazon, Microsoft, Bloomberg, TikTok, and Snap. The acceptance rate sits around 62 percent, which means a solid chunk of candidates nail it but plenty hit a wall on the combinatorial insight. The trick isn't building trees, it's counting them without building anything. If you blank on the recurrence during a live OA, StealthCoder solves it invisibly in seconds and surfaces the working solution before your proctor notices.

Companies asking
12
Difficulty
MEDIUM
Acceptance
62%

Companies that ask "Unique Binary Search Trees"

If this hits your live OA

Unique Binary Search Trees is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

The problem asks for the count of structurally unique binary search trees given n nodes. Most candidates start building actual trees, which is slow and conceptually wrong. The real pattern is dynamic programming on structure: if you fix node i as the root, you get all valid left subtrees from nodes 1 to i-1 and all valid right subtrees from i+1 to n. The answer at each position n is the sum across all roots of (count of left subtrees) times (count of right subtrees). This is a classic catalan number scenario. The insight lives in realizing you don't need to construct anything, just compute counts bottom-up from 1 to n. Common miss: trying to track actual tree shapes instead of recognizing the multiplicative structure. When you hit this live and the greedy or recursive-with-memoization approaches feel clunky, StealthCoder provides the clean DP formulation instantly.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Unique Binary Search Trees recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Unique Binary Search Trees interview FAQ

Is this actually asked at Amazon and Microsoft?+

Yes. It appears in Amazon's OA pipeline and Microsoft's interviews frequently. The problem tests whether you can extract the combinatorial core from a tree problem, which is a skill they care about. Medium difficulty and 62 percent acceptance rate suggest it's a gating problem, not a warm-up.

Why can't I just generate all the trees?+

You can, but it's exponential in time and space. The problem only asks for the count, and the count follows Catalan numbers. Building trees is the trap answer. The DP approach computes the count in O(n^2) or O(n^3) depending on implementation, which passes.

What's the core trick I need to remember?+

Fix each node as root. Left subtrees come from smaller numbers, right from larger. Multiply counts of left and right possibilities, then sum across all root choices. That's it. The recursion is G(n) = sum of G(i-1) * G(i+1) for i from 1 to n, where G(0)=1.

How does this relate to the other tree and DP topics?+

It's pure combinatorics disguised as a tree problem. Binary Search Tree constraints (left less, right greater) guarantee structural uniqueness for any given arrangement. The DP tracks how many such arrangements exist, without building them. Math underpins the entire solution.

Will I see this in coding interviews at Tower Research, TikTok, or Snap?+

Yes, all three report asking it. Tower Research and Snap especially use tree and math problems to filter candidates on algorithmic insight. If you're interviewing there and this hits your OA, it's a high-signal problem. Don't guess, solve it cleanly or hedge with a tool.

Want the actual problem statement? View "Unique Binary Search Trees" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.