FastPrepNodes at a Given N-ary Tree Level
Problems/Nodes at a Given N-ary Tree Level

Nodes at a Given N-ary Tree Level

Amazon logoAmazon● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon SDE2 interview list as returning N-ary tree nodes at a requested level. The brief report leaves the tree representation, level base, result order, missing-level behavior, and limits unstated. In this exercise, node 0 is the root, each child-ID list is ordered left to right, levels are zero-based, results preserve that order, and a missing level returns an empty array. Problem match confidence: approximately 87%.

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 = 2return = [4,5]

Only nodes 4 and 5 are two edges from the root.

Example 2

children = [[]]level = 0return = [0]

Level zero contains the root.

Example 3

children = [[1],[2],[3],[]]level = 3return = [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.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public int[] nodesAtLevel(int[][] children, int level) {
        // write your code here
    }
}
Checking account…