All practice tasks

Coding (Algo)

Measure the Busiest Tree Level

Tree traversal · Easy

A tree viewer allocates one row of controls for each depth. It needs the largest number of actual nodes on a single row. Missing heap slots are not controls, so counting the span between the leftmost and rightmost index would allocate unnecessary capacity.

Return the maximum number of reachable nodes at any one depth counting actual nodes rather than index gaps.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

{ tree: (integer | null)[] }

Fields

  • tree is a binary tree encoded with heap indexes: root 0; children of i are 2i+1 and 2i+2. This is not compact queue serialization.
  • Null parents make their descendants unreachable. Values do not affect this structural measurement.

Output

Return value

  • Return an integer count. Empty input or a null root returns zero.
  • Null holes and unreachable descendants never contribute. A singleton tree has width one.

Constraints

  • 0 <= tree.length <= 100000; each non-null value is an integer from -1000000000 to 1000000000.
  • Do not mutate either input array. Sums fit safe JSON integers. Heap indexing bounds the tree height by 17 at this input limit.

Examples

Example 1

{
  "tree": [
    1,
    2,
    3,
    4,
    null,
    null,
    7
  ]
}

Returns

2

Example 2

{
  "tree": [
    1
  ]
}

Returns

1

Required complexity

O(n) time and O(h) auxiliary traversal space excluding the returned output

What this task practices

Measure the Busiest Tree Level is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as easy difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.