Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: A tree has 7 nodes labelled 1–7 with edges 1-2, 1-3, 3-4, 3-5, 5-6, 5-7. Node 1 is the root. What is the depth of the deepest node (root depth 0)?
- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
A BFS from the root gives each node's depth, and the maximum is the answer. Counting the number of leaves or the root's degree measures something else.
More Coding Interview Problems questions
- Problem: Strings "axbycz" and "abc" are given. Count the subsequences of "axbycz" that equal "abc" (indices must be increasing, and…
- Problem: Starting with the list [1, 2, 3, 4, 5, 6], repeatedly remove every second element (keeping the first) until one element remains…
- Problem: In the array [5, 1, 4, 2, 8, 0, 2], count the pairs (i, j) with i < j and a[i] > 2·a[j] (so a[i] is more than double a[j]).
- Problem: The string "aabcbbca" is processed by a sliding window that keeps at most one distinct letter 'a' inside (other letters are…
- Problem: How many integers in [1, 200] are divisible by exactly one of 6 and 8?
- Problem: The Euler's criterion test: count the quadratic residues modulo 13 among 1 through 12 (a residue r satisfies x² ≡ r for some…