Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: A complete binary tree has 15 nodes (height 3, all levels full). How many of its nodes are leaves?
- A. 7
- B. 16
- C. 4
- D. 8
Correct answer: D. 8
A full tree of height 3 has 1 + 2 + 4 + 8 nodes, and the bottom level holds 2³ = 8 leaves. 7 counts the internal nodes, 2⁴ = 16 uses the wrong level, and 4 is the level above.
More Coding Interview Problems questions
- Problem: The string "abba" has how many palindromic substrings (counted by index range)?
- Problem: How many occurrences of "ab" are in "ababab" when occurrences may overlap?
- Problem: In the string "dvdf", what is the length of the longest substring with all distinct characters?
- Problem: The number of ways to tile a 1×4 strip completely using tiles of length 1 and length 2 (tiles of the same length are…
- Problem: In the binary string "0011100", what is the length of the longest contiguous substring that contains equal numbers of 0s and 1s?
- Problem: How many strings of length 3 over the alphabet {a, b, c} contain no two consecutive a's?