Reported July 2026
Ripplingtree

Limit an Organization Tree's Height

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

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

Rippling's July 2026 OA reports include a tree problem where the CEO is employee 1 and you can re-hang any non-CEO employee directly under the CEO. The first ask is easy: find the deepest level. The follow-up is the real test: hit a maxHeight cap with the fewest moves. It's a tree DFS with a greedy twist, and the examples hide the trick well. If you blank mid-assessment, StealthCoder runs invisibly on your desktop and reads the problem for you. Here's the pattern so you don't need it.

The problem

An organization has n employees numbered from 1 to n. Employee 1 is the CEO. Each pair managers[i], reportees[i] is a directed edge from a manager to a direct report. The edges form a rooted tree.
An employee's level is its number of edges from the CEO, so the CEO is at level 0. The tree's height is its maximum employee level.
Restructuring Rule
The organization wants height at most maxHeight. In one change, choose any non-CEO employee and make that employee report directly to the CEO. The employee's entire subtree moves with them and otherwise remains unchanged.
Return [originalHeight, minimumChanges], where minimumChanges is the fewest direct-report changes needed to make the final height at most maxHeight.
Interviewer follow-ups
The interview begins by asking for the deepest employee level. The follow-up adds the maximum-height policy and asks candidates to minimize how many employees must become direct reports of the CEO.

Function
analyzeOrgTree(n: int, managers: int[], reportees: int[], maxHeight: int) → int[]

Examples
Example 1
n = 6
managers = [1,2,3,4,1]
reportees = [2,3,4,5,6]
maxHeight = 2
return = [4,1]
The chain 1-2-3-4-5 gives an original height of 4. Making employee 3 report to the CEO changes that chain to 1-3-4-5, whose deepest level is 3, so it does not satisfy maxHeight = 2. Instead, make employee 4 report to the CEO, leaving employee 5 at level 2. One change is sufficient.
Example 2
n = 5
managers = [1,1,2,2]
reportees = [2,3,4,5]
maxHeight = 2
return = [2,0]
The original tree already has height 2, so no direct-report change is needed.

Constraints
2 <= n <= 200000
managers.length = reportees.length = n - 1
1 <= maxHeight < n
The edges form a tree rooted at employee 1.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Build the child lists, then compute each node's level and its subtree height (longest path down to a leaf). Moving a node to the CEO puts it at level 1, so its deepest descendant lands at 1 + height(node). The greedy: process bottom-up, and cut a node exactly when its height reaches maxHeight - 1 and it isn't already a direct report of the CEO. Cutting resets that subtree, so the parent sees a smaller height. Pitfall: cutting too high, like employee 3 in Example 1, which still leaves depth 3. Cut the deepest-possible node, the one whose subtree height hits the limit. Use an iterative DFS or BFS order because n goes to 200000 and recursion will overflow. The first answer is just the max level. StealthCoder is your hedge if the greedy argument escapes you live, but the post-order count is short once you see it.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Limit an Organization Tree's Height 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Rippling reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Limit an Organization Tree's Height FAQ

What's the trick in this Rippling org tree problem?+

Go bottom-up with subtree heights. When a non-CEO node's height (edges down to its deepest leaf) reaches maxHeight - 1 and its parent isn't the CEO, cut it to the CEO and count one change. Cutting low and late removes the most depth per move.

Why not just move the deepest employee to the CEO?+

Moving a leaf only shortens that leaf's path. Its ancestors stay deep and nothing else improves. Moving the node whose subtree would otherwise hit the limit resets that whole branch, so one move can fix many deep employees at once.

How do I get originalHeight?+

Run BFS or DFS from employee 1 and track the level of each node. The maximum level is originalHeight. Build an adjacency list from managers and reportees first. Edges are directed, so you only need to follow manager to reportee.

Will recursion work with n up to 200000?+

Not safely. A chain of 200000 employees will overflow the stack in most languages. Get a BFS order from the CEO, then process that order in reverse to compute subtree heights iteratively. It's O(n) time and memory.

How do I prepare for this in 48 hours?+

Practice rooted-tree height computation with an iterative post-order pass, then add the greedy cut rule. Test Example 1 by hand, plus a case where the tree is already within maxHeight. Also check the star shape and a pure chain.

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

OA at Rippling?
Invisible during screen share
Get it