Data Structures & AlgorithmsModerateTCS NQT Digital · Product Company SDE
Problem: In the array [2, 9, 4, 7, 1, 8], find the 4th smallest element using the quickselect idea (its final answer is the value that would sit at sorted index 3, 0-based).
- A. 8
- B. 4
- C. 7
- D. 2
Correct answer: C. 7
Sorted, the array is [1, 2, 4, 7, 8, 9], so sorted index 3 holds 7, which quickselect returns. Treating 4th as index 4 gives 8, the 4th largest is 4, and returning the first pivot unpartitioned gives 2.
More Coding Interview Problems questions
- Problem: In the sorted array [1, 2, 4, 7, 8, 11, 13], how many pairs (i, j) with i < j have a[j] − a[i] ≤ 2?
- Problem: Piles of bananas are [3, 6, 7, 11] and you must finish all of them within 8 hours. Each hour you eat up to k bananas from one…
- Problem: Intervals [1,4], [3,8], [6,9], [10,12], [2,5] are given. How many of them contain the point 5 (endpoints included)?
- Problem: Compute (1³ + 2³ + … + 100³) modulo 1000.
- Problem: A trie stores the words "apple", "app", "apply", "ape", "banana". How many stored words start with the prefix "app" (including a…
- Problem: Subtraction game: from n stones a player may remove 1, 3 or 4 stones; the player who cannot move loses (no stones left on their…