LeetCode 178: Rank Scores
Solved: Rank Scores Problem on LeetCode 178
I'm Varchasv, a Data Engineer working on enterprise data integration.
Currently on a 90-problem challenge to level up my technical skills and switch to a more development-focused role.
What I'm doing:
- Solving 2 Leetcode problems daily (SQL + DSA).
- Blogging about each problem.
- Building in public.
My Goal - Land a better data engineering role by mid-2026.
Follow my journey !!
Date: February 03, 2026
Category: SQL
Time Taken: 2 minutes
Difficulty: Medium
Problem Statement
Write a solution to find the rank of the scores. The ranking should be calculated according to the following rules:
The scores should be ranked from the highest to the lowest.
If there is a tie between two scores, both should have the same ranking.
After a tie, the next ranking number should be the next consecutive integer value. In other words, there should be no holes between ranks.
Return the result table ordered by score in descending order.
Link: Rank Scores
My Approach
This is a classic Window Function problem. Since we need to assign the same ranking to tied scores and ensure the next ranking is the consecutive integer value without skipping, we will use
DENSE_RANK().We will order by score in descending order to give the highest scores the top ranks.
Solution Code:
SELECT score, DENSE_RANK() OVER(ORDER BY score DESC) AS `rank`
FROM Scores
Pattern: Window Functions
Mistakes I Made: Very Simple, DENSE_RANK() solution.
Series: 90 Days of Data Engineering Progress: 30/90 problems completed
Tags: #DEQuest #LeetCode #SQL #DataEngineering #BuildInPublicLee