Data Structures & AlgorithmsHardTCS NQT · Product Company SDE
Problem: Lomuto partition uses the last element as the pivot on [3, 8, 2, 5, 1, 4, 7, 6]. After one partition pass, at what index (0-based) is the pivot placed?
- A. 6
- B. 4
- C. 7
- D. 5
Correct answer: D. 5
Lomuto partition keeps a boundary of values not greater than the pivot and finally swaps the pivot into the boundary position. Using the first element as the pivot gives a different final index.
More Coding Interview Problems questions
- Problem: Five numbers 1, 2, 3, 4, 5 are inserted in that order into an initially empty min-heap (array form, sift-up after each…
- Problem: Binary search for the value 77 in the sorted list 1, 2, ..., 100 uses the midpoint mid = (lo + hi) // 2 and the inclusive range…
- Problem: What is the value of the lowest set bit of 96 (the largest power of 2 dividing 96)?
- Problem: For the numbers 1, 2, 3, 4, 5, how many unordered pairs (i, j) with i < j have i XOR j strictly less than 4?
- Problem: What is the sum of the proper divisors of 220 (divisors less than 220)?
- Problem: What is the smallest positive integer n such that 1 + 2 + … + n is divisible by 10?