Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: A rooted tree (root 1) has children 1: [2, 3], 2: [4], 3: [5, 6], 5: [7]. What is the number of nodes at depth 2 (root at depth 0)?
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
Depth-2 nodes are the grandchildren of the root: 4, 5 and 6. Counting leaves instead gives a different number.
More Coding Interview Problems questions
- Problem: The string "mississippi" contains repeated substrings. What is the length of the longest substring that appears at least twice…
- Problem: For the string "abcabcdab", how many substrings of length 3 occur exactly once?
- Problem: How many integers from 1 to 500 are NOT perfect squares and NOT perfect cubes?
- Problem: The dynamic array doubles its capacity whenever it is full, starting from capacity 1. After inserting 9 elements one by one, how…
- Problem: In a binary heap stored in an array with 1-based indexing, the array [1, 3, 2, 7, 4, 5, 6] is a valid min-heap. What is the sum…
- Problem: Vertices 0–5 form a graph with edges 0-1, 1-2, 2-3, 3-0 and 4-5. A BFS from vertex 0 gives each vertex a distance. What is the…