Data Structures & AlgorithmsHardTCS NQT · Product Company SDE
Problem: The array [5, 3, 8, 6, 2, 7] is processed by the partition step of quicksort with pivot = first element (5), using the Hoare-style pivot exchange: count the elements strictly less than the pivot that lie to its right of the pivot's final boundary. Report that count.
- A. 3
- B. 2
- C. 1
- D. 4
Correct answer: B. 2
The number of elements smaller than the pivot determines where the pivot lands in the partition. Here 3 and 2 are smaller than 5, so the count is two.
More Coding Interview Problems questions
- Problem: Starting with the number 100, subtract the square of the smallest prime factor of the current number each step (the number is…
- Problem: The string "xyzxyzxyz" is split into 3 equal blocks of length 3. The blocks are compared: how many pairs of blocks (i < j) are…
- Problem: From the list of integers [10, 15, 20, 25, 30], remove the elements that are divisible by 4 or by 6 (the rest remain in order)…
- Problem: The number 1729 is written in base 10. What is the sum of its digits in base 12, given as the digit sum of 1729 written in base 12?
- Problem: A sorted list has values 3, 7, 7, 9, 12, 12, 12, 15. How many distinct values lie within the range [7, 12] inclusive?
- Problem: On a 3×3 grid, each cell is labelled with its row times column (1-indexed). The number of cells whose label is a perfect square…