Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys
Problem: Starting from the empty set, a process inserts the numbers 5, 3, 8, 1, 4, 7 into a binary search tree, and then deletes nothing. How many nodes lie in the left subtree of the root?
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
The root is 5; values below it (3, 1, 4) form the left subtree. Counting all nodes in the tree instead of the left subtree gives 6.
More Coding Interview Problems questions
- Problem: The array [4, 2, 5, 1, 3] is turned into a max-heap by sift-down from the last parent to the root (standard heapify, 0-indexed)…
- Problem: A string is "racecar" and we ask: how many substrings of length 2 or 3 are palindromes (counted by index ranges)?
- Problem: The array [6, 1, 9, 4, 4, 8] is scanned, and for each index the number of earlier elements that are strictly smaller is recorded…
- Problem: The array [1, 5, 2, 6, 3, 7, 4, 8] is split into two halves, [1, 5, 2, 6] and [3, 7, 4, 8]. The result is formed by interleaving…
- Problem: How many integers from 1 to 1000 are perfect squares or perfect cubes (counted once even if both)?
- Problem: An undirected graph has edges 0-1, 1-2, 2-3, 3-4, 4-0, 1-5, 5-6, 6-2. What is the length of the shortest cycle that passes…