Reported July 2026
Snowflaketree

Distributed Tree Counting State Machine

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

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

Snowflake's July 2026 OA reports include this one, and the input size is the tell: parent.length is at most 500, so nothing here needs cleverness for speed. It's a tree problem dressed up as a distributed systems question. You build children lists from the parent array, then run a FIFO message queue and log every send. The trap is ordering, not complexity. If you blank on the queue mechanics during the assessment, StealthCoder is the safety net running invisibly on your screen. Here's the script.

The problem

Simulate a nonblocking count protocol over a rooted tree. Node i knows only its parent, its direct children, and local aggregation state. The array parent defines the tree: node 0 is the root, and for each i > 0, parent[i] is its parent.
The harness starts one GET_COUNT request at the root. An internal node that receives GET_COUNT asynchronously sends the same request to each child in increasing node-id order. A leaf immediately reports 1 to its parent. An internal node waits without blocking across separate message deliveries, then reports 1 plus all child counts after every child has responded. The root exposes that total instead of sending it upward.
Messages are delivered exactly once by one FIFO queue. Record each call to sendAsync as from->to:GET_COUNT or from->to:REPORT_COUNT:value. After the root completes, append ROOT_COUNT:value. Return the complete trace.
Unreliable-network follow-up
In a real unreliable network, attach a request identifier to every message, make reports idempotent per child and request, acknowledge messages, retry unacknowledged messages with a bounded policy, and retain completed-request state long enough to answer duplicates. These reliability mechanisms are discussion requirements and do not change the judged FIFO outputs.

Function
simulateTreeCount(parent: int[]) → String[]

Examples
Example 1
parent = [-1,0,0,1,1]
return = ["0->1:GET_COUNT","0->2:GET_COUNT","1->3:GET_COUNT","1->4:GET_COUNT","2->0:REPORT_COUNT:1","3->1:REPORT_COUNT:1","4->1:REPORT_COUNT:1","1->0:REPORT_COUNT:3","ROOT_COUNT:5"]
The root first contacts nodes 1 and 2. FIFO delivery lets node 1 enqueue requests to its children before node 2 reports. Node 1 reports only after both child reports arrive, and the root then completes with all five nodes.
Example 2
parent = [-1]
return = ["ROOT_COUNT:1"]
The root is also a leaf, so it completes immediately without sending a message.

Constraints
1 <= parent.length <= 500
parent[0] == -1.
For every i > 0, 0 <= parent[i] < i, so the input is one rooted tree and children are discovered in increasing node-id order.
The judged base simulation has one active request and delivers each emitted message exactly once in FIFO order.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to stop thinking recursively. Build children lists in increasing id order (the parent[i] < i constraint makes this a simple loop). Push the root's GET_COUNT sends onto a queue, then pop messages one at a time. On GET_COUNT delivery: if the node is a leaf, enqueue REPORT_COUNT:1 to its parent. Otherwise enqueue GET_COUNT to each child in order. On REPORT_COUNT delivery: add the value to the parent's running total, decrement its pending counter, and when pending hits zero, enqueue its report of 1 plus total, or append ROOT_COUNT if it's the root. Log the string at the moment of each enqueue, not at delivery. That's the common pitfall, and it breaks the trace order. A DFS gives the wrong trace. Handle the single-node case up front. The unreliable-network follow-up is discussion only, so don't code it. StealthCoder is your hedge if the queue logic slips live.

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 Distributed Tree Counting State Machine 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 Snowflake's OA.

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

Distributed Tree Counting State Machine FAQ

How hard is the Snowflake tree counting simulation really?+

Easy on algorithm, fiddly on detail. With 500 nodes, complexity is a non-issue. The difficulty is reproducing the exact FIFO trace order. Walk Example 1 by hand once and you'll see where each string gets logged.

What's the trick to getting the trace order right?+

Use a single queue and record each sendAsync string when you enqueue the message, not when you deliver it. A recursive DFS gives a different order than FIFO. BFS-style delivery is what produces the expected output.

Do I need to implement retries and idempotency for the unreliable network part?+

No. The problem says those mechanisms are discussion requirements and don't change the judged FIFO outputs. Code only the base simulation. Be ready to explain request IDs, acknowledgments, bounded retries, and retained state for duplicates if asked.

What edge cases should I test?+

Test a single node, which should return only ROOT_COUNT:1 with no messages. Also test a chain, a star, and the sample with two levels of children. Check that a node reports only after every child has responded.

How do I prepare for this in 48 hours?+

Practice event-driven simulation with a queue and per-node pending counters. Build children lists from a parent array, then write the loop that handles two message types. Run both examples by hand and compare strings character by character.

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

OA at Snowflake?
Invisible during screen share
Get it