Rank with gaps
Implement SQL RANK() OVER (ORDER BY score DESC). Given a list of [name, score] rows, assign each a rank: the highest score gets rank 1, and ties share the same rank with the next distinct score skipping ranks (standard RANK, not DENSE_RANK). Return [name, rank] pairs sorted by rank ascending, then name ascending within the same rank. Scores are integers; up to 5000 rows.
Implement
rank_window(rows: list[list]) → list[list]Examples
in
[[["a",90],["b",90],["c",80]]]out[["a",1],["b",1],["c",3]]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 22 min
solution.py
InputExpectedGot
[[["a",90],["b",90],["c",80]]][["a",1],["b",1],["c",3]]not run yetsample