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?

  1. A. cy
  2. B. dee
  3. C. eve
  4. 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

Exams that ask this topic