Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: Tree with root 1 and children 1: [2, 3], 2: [4, 5], 4: [6]. What is the number of nodes in the subtree of node 2 (node 2 counts itself)?
- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: C. 4
The subtree of node 2 contains 2, 4, 5 and 6, which is four nodes. Counting only the leaves under node 2 gives two.
More Coding Interview Problems questions
- Problem: The string "abracadabra" contains the substring "abra" at several positions. How many occurrences of "abra" are there (overlaps…
- Problem: The string "abcdefghij" is split into blocks of length 4 from the left (the last block may be shorter). How many blocks have…
- Problem: The number of permutations of the digits 1, 2, 3, 4 in which the digit 1 is not in the first position and 4 is not in the last…
- Problem: Cars pass a toll booth at times 2, 5, 6, 10, 11, 15 (minutes). A car may pass only if at least 3 minutes have elapsed since the…
- Problem: A sorted list of distinct integers is 3, 8, 12, 17, 21, 26, 30. How many pairs (i < j) have a[j] − a[i] exactly equal to 9?
- Problem: The value of 3^(3^3) mod 7 is what?