Skip to content

Practice Rank Scores

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#178
LeetCode Problem

Rank Scores

Problem Statement

Tables: Scores(id INT, score DECIMAL). Scores.id is unique; score has two decimal places. Return score and its rank, ordered by score descending. Equal scores share a rank and the next different score receives the next integer rank, with no gaps. Dense ranking over descending scores implements this rule.

Source: Rank Scores on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
Scores table: +----+-------+ | id | score | +----+-------+ | 1  | 3.50  | | 2  | 3.65  | | 3  | 4.00  | | 4  | 3.85  | | 5  | 4.00  | | 6  | 3.65  | +----+-------+
Output
+-------+------+ | score | rank | +-------+------+ | 4.00  | 1    | | 4.00  | 1    | | 3.85  | 2    | | 3.65  | 3    | | 3.65  | 3    | | 3.50  | 4    | +-------+------+

Related LeetCode Problems

Practice more problems similar to Rank Scores.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.