A spreadsheet holds rows, a list of tuples that all have the same length. The user clicks column headers one after another; each click stably re-sorts the current rows by that column in ascending order (rows with equal values in that column keep their current relative order).
Given rows and the list clicks of column indices in the order they were clicked, return the rows in their final order. clicks may be empty or repeat a column.
Examples
Input: rows = [("ann", "eng", 30), ("bob", "ops", 25), ("cat", "eng", 25), ("dan", "ops", 30)]
clicks = [2, 1]
Output: [("cat", "eng", 25), ("ann", "eng", 30), ("bob", "ops", 25), ("dan", "ops", 30)]
Explanation: After clicking column 2 (age): bob, cat, ann, dan. Clicking column 1 (dept) then
groups by department while keeping that age order inside each department.
Constraints
0 <= len(rows) <= 5 * 10**4,0 <= len(clicks) <= 10- Every column holds values of a single comparable type.
- Target complexity: O(c * n log n) for
cclicks.
Goals
- Rely on the stability of Python's sort to simulate successive sorts
- Understand that the most recent sort dominates and earlier sorts break ties
- Handle repeated and empty click sequences