Data Structures & AlgorithmsModerateTCS NQT Digital · Product Company SDE
Problem: A height-balanced binary search tree is built over the sorted keys 1, 2, …, 10 by always taking the middle element as the root. What is the height of the tree (number of levels, so a single node has height 1)?
- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: C. 4
Choosing the middle key as the root halves each subproblem, giving the minimum possible height. Choosing the first key as root produces a chain of height 10.
More Coding Interview Problems questions
- Problem: Given the parent array p = [−1, 0, 0, 1, 1, 2, 4, 4] for nodes 0–7 (node 0 is the root), how many nodes have exactly one child?
- Problem: A binary tree in level order (None for absent nodes) is [5, 4, 8, 11, None, 13, 4, 7, 2, None, None, 5, 1]. How many root-to-leaf…
- Problem: Count the odd-length palindromic substrings of "racecarxyz" that are centred at index 3 (the 'e' of "racecar"), where the centre…
- Problem: What is the lexicographically next permutation of the string "bcdea" (the next arrangement in dictionary order using the letters…
- Problem: How many substrings of "abcabc" contain all three letters a, b and c at least once?
- Problem: In how many ways can a 1 × 7 strip be tiled completely with tiles of length 1, 2 and 3 (ordered arrangements of tiles count…