Code Room
CodingMediumcod-g1158
Subject Database window functionsLevel Mid–Senior~22 minCommon in Databases & SQL interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.