Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: A binary tree is given in level order with None for missing children: [1, 2, 3, None, 4, 5, None, 6]. In this array, node at index i has children at 2i+1 and 2i+2 (when present). How many nodes have both children present?

  1. A. 2
  2. B. 0
  3. C. 1
  4. D. 3

Correct answer: C. 1

Use the index formula to find each node's children and count the nodes whose two child slots are both filled. Counting nodes with at least one child gives a larger count.

More Coding Interview Problems questions

Exams that ask this topic