Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: For the same rooted tree as the previous question (root 1: children 2, 3; 2: children 4, 5, 6; 3: child 7; 5: child 8; 7: child 9), what is the height of the tree (the largest depth of any node, with the root at depth 0)?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
Height is the maximum depth over all nodes, found with one traversal that carries depth. Counting the number of leaves or the root's degree is a different measure.
More Coding Interview Problems questions
- Problem: In a binary tree with 7 nodes in level order [10, 5, 15, 2, 7, 12, 20] (missing children are shown as absent, so the array…
- Problem: Three sorted rows are [1, 5, 9, 14], [2, 6, 10, 15] and [3, 7, 11, 16]. Merging all rows into one sorted sequence, what is the…
- Problem: What is the length of the longest substring of "abcabcbb" with all characters distinct?
- Problem: The shortest palindrome obtainable by inserting characters only at the front of "abacd" has what length?
- Problem: How many distinct palindromic substrings does "abacaba" contain (single characters count as palindromes, and distinct strings…
- Problem: Among all distinct permutations of the letters A, B, C, D, arranged in dictionary order starting from rank 1, what is the rank of…