Skip to main content

Command Palette

Search for a command to run...

LeetCode 178: Rank Scores

Solved: Rank Scores Problem on LeetCode 178

Published
1 min read
V

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

90 Days of Data Engineering

Part 31 of 48

Solving 90 problems over 18 weeks. Daily posts Mon-Fri. Goal: Switch to development role.

Up next

LeetCode 169: Majority Element

How to Solve LeetCode 169: The Majority Element