Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: Records (name, score) are sorted by score descending with Python's stable sort: [("ann",80),("bob",95),("cy",80),("dee",95),("eve",70)] sorted by key=lambda r: -r[1]. What is the name at index 2 of the result?
- A. cy
- B. dee
- C. eve
- D. ann
Correct answer: D. ann
Python's sort is stable, so equal scores keep their original relative order. The third entry is the first 80-scorer, not the first 95-scorer shifted; reversing the sort flips ties and changes the answer.
More Coding Interview Problems questions
- Problem: A deque holds 1, 2, 3, 4, 5 from left to right. The operation rotate(2) moves the last 2 elements to the front (rotate right by…
- Problem: A 2D prefix-sum table is built for the grid [[1,2,3],[4,5,6],[7,8,9]]. What is the sum of the submatrix with rows 1–2 and columns…
- Problem: A sparse-table-free query: over the array [5, 2, 8, 1, 9, 3, 7], what is the minimum value on the range of indices [2, 5]…
- Problem: A Fenwick tree (binary indexed tree) over positions 1–8 starts with all zeros. The operations are: add 5 at position 3, add 4 at…
- Problem: Compute the 50th Fibonacci number F(50) with F(1) = F(2) = 1, modulo 1,000,000,007.
- Problem: Compute C(20, 10) modulo 1,000,000,007 (the binomial coefficient).