Reported September 2026
Snaptree

Render an Org Chart and Find Skip-Level Pairs

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

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

Snap reported this one in September 2026, and the whole problem hinges on one structure: an adjacency map from manager to ordered children. Build that, find the root, and the rest is a clean preorder walk. The prompt dresses it up as an org chart with dot prefixes and skip-level pairs, but it's a tree traversal with two outputs from one pass. If you're taking this OA soon, know the shape before you touch the keyboard. StealthCoder is there as a safety net if you blank mid-assessment, but this one is very doable if you set up the map correctly.

The problem

An organization tree is given as relations. Each row contains a manager followed by that manager's direct reports, in display order. Every employee name is unique, every non-root employee has exactly one manager, and the rows describe one valid tree.
Return a two-row result:
Row 0 contains the full preorder rendering. The root has no prefix; an employee at depth d is prefixed by exactly 4 * d period characters.
Row 1 contains every skip-level pair manager->employee for which the employee is exactly two edges below the manager. Order pairs by the preorder position of the manager and then the preorder position of the employee.

Function
analyzeOrgChart(relations: String[][]) → String[][]

Examples
Example 1
relations = [["A","B","C"],["B","E"],["C","D"]]
return = [["A","....B","........E","....C","........D"],["A->E","A->D"]]
E and D are the grandchildren of A.
Example 2
relations = [["M","N"],["N","P"],["P","Q"]]
return = [["M","....N","........P","............Q"],["M->P","N->Q"]]
Each length-two ancestor path contributes one pair.

Constraints
1 <= relations.length <= 100000.
Each row contains a manager and zero or more direct reports.
The total number of employees is at most 100000.
Names are nonempty ASCII strings without ->.
The input describes one valid rooted tree.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is a map from each manager to its list of direct reports, kept in input order. Find the root as the one name that never appears as a report. Then run a preorder DFS that carries depth. At each node, emit 4 * depth dots plus the name. For skip-level pairs, the grandchildren of a node are the children of its children, so when you visit a node you loop its children and their children and record pair strings. Because you visit managers in preorder and loop grandchildren in order, the ordering falls out for free. The pitfall is recursion depth. With up to 100000 employees, a chain tree will overflow the stack in most languages, so use an explicit stack and push children in reverse. Also don't sort anything. If you freeze up on the iterative version during the live OA, StealthCoder can hand you the skeleton.

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 Render an Org Chart and Find Skip-Level Pairs 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

⏵ The honest play

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

Snap 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.

Render an Org Chart and Find Skip-Level Pairs FAQ

What's the core trick in the Snap org chart problem?+

Build a map from manager to ordered list of direct reports, find the root as the name never listed as a report, then do a preorder traversal with depth. Skip-level pairs come from looping each node's children's children during that same traversal.

How do I find the root?+

Collect every name that appears as a direct report into a set. The root is the manager name that isn't in that set. Since the input is one valid tree, exactly one such name exists. A single pass over the rows is enough.

Will recursion break on 100000 employees?+

Yes, it can. A long chain gives a depth of 100000, which overflows the default stack in many languages. Use an explicit stack, pushing children in reverse order so they pop in display order. That keeps preorder correct and avoids the crash.

How do I get the skip-level pair order right?+

Process managers in preorder, and for each one, iterate its children in order and then each child's children in order. That matches the required ordering by manager position then employee position. No sorting is needed, and sorting would likely break it.

How should I prepare in 48 hours?+

Practice one iterative preorder traversal on a map-based tree and one string-building problem with depth-based prefixes. Watch for leaf managers with empty report lists and for names that only appear as reports. Test your code on both examples, including the single-chain one.

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

OA at Snap?
Invisible during screen share
Get it