Reported September 2026
Amazonbreadth first search

Nodes at a Given N-ary Tree Level

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

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

The edge case that kills the lazy solution on this Amazon OA, reported in September 2026, is a level that doesn't exist. Ask for level 100000 on a tree with five nodes and your code had better return an empty array, not crash or loop. The problem is a plain level-order traversal of an N-ary tree, given as an adjacency list with root 0. It's easy to write and easy to get slightly wrong. If you blank on the live assessment, StealthCoder runs invisibly on your desktop and hands you the working solution, but the pattern here is short enough to own tonight.

The problem

An N-ary tree uses node IDs from 0 through children.length - 1, with root ID 0. For each node ID, children[id] lists its child IDs from left to right.
Return the node IDs at zero-based level in left-to-right breadth-first order. Return an empty array when no nodes exist at that level.

Function
nodesAtLevel(children: int[][], level: int) → int[]

Examples
Example 1
children = [[1,2,3],[4,5],[],[],[],[]]
level = 2
return = [4,5]
Only nodes 4 and 5 are two edges from the root.
Example 2
children = [[]]
level = 0
return = [0]
Level zero contains the root.
Example 3
children = [[1],[2],[3],[]]
level = 3
return = [3]
The skewed tree has one node at level three.

Constraints
1 ≤ children.length ≤ 100000.
The child lists describe one valid rooted tree containing every node exactly once.
0 ≤ level ≤ 100000.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Run a breadth-first search from node 0, processing one full level at a time. Keep a current-level array. Start with [0] at depth 0. While depth is less than the target level, build the next level by appending every child of every node in the current one. If the next level comes up empty before you reach the target, return an empty array right away. That's the edge case. At depth equal to level, return the current array. Order is free, because iterating nodes left to right and children left to right keeps the output ordered. The pitfall is recursion. With up to 100000 nodes, a skewed tree like Example 3 will blow the stack in a DFS. Stay iterative. Total work is O(n) and you can stop early. If you freeze during the live OA, StealthCoder is the safety net that gives you this loop while you stay in control of the submission.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Nodes at a Given N-ary Tree Level 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Amazon reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Nodes at a Given N-ary Tree Level FAQ

How hard is the Nodes at a Given N-ary Tree Level problem really?+

Easy. It's a level-order BFS on an adjacency list. The difficulty is in the details: stopping early when a level is empty, handling level 0, and not using recursion on a 100000-node skewed tree. If you've written BFS before, it's a ten-minute problem.

What's the trick to getting it right the first time?+

Process BFS level by level instead of node by node. Keep a current array, build a next array from all children, and swap. Count levels as you go. When current becomes empty before you hit the target level, return []. No visited set is needed because it's a tree.

Should I use DFS or BFS here?+

BFS. It gives left-to-right order per level naturally and avoids stack depth problems. A DFS can work if you track depth and collect nodes at the target, but a chain of 100000 nodes risks stack overflow in many languages. Iterative BFS is the safer pick.

What edge cases should I test before submitting?+

Test a single node with level 0, which returns [0]. Test a single node with level 1, which returns []. Test a skewed chain where the level equals the last depth. Test a level far beyond the tree height, like 100000. Also check a wide root with many leaf children.

How do I prepare for this Amazon OA in 48 hours?+

Write BFS from memory three ways: queue-based, level-by-level with two arrays, and with depth tracking. Then do a few tree and graph traversals on adjacency lists. This problem reported in September 2026 is a warm-up pattern, so speed and clean edge handling matter more than cleverness.

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

OA at Amazon?
Invisible during screen share
Get it