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?
- A. 2
- B. 0
- C. 1
- 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
- Problem: The right-side view of a binary tree lists the rightmost node at each depth from top to bottom. For the tree with root 1…
- Problem: A binary tree is given by level order [1, 2, 3, 4, 5, None, 6]. Its diameter is the largest number of edges on any path between…
- Problem: How many palindromic substrings of even length does "abbaccdd" contain?
- Problem: The string "aaaa" can be written as a concatenation of the pieces "a" and "aa" in several ways (order matters). How many such…
- Problem: The minimum ASCII delete sum to make the strings "sea" and "eat" equal is the least total ASCII value of deleted characters. Give…
- Problem: A pattern-matching task uses the string "abxcabcyabd" and the target "abc". How many length-3 windows of the text differ from…