Rank Scores with Gaps

ASKED IN INTERVIEW
4pts
Meta

Problem Statement

Meta needs to rank users based on their engagement scores. If two users have the same score, they should both receive the same rank. However, the next rank in the sequence must be skipped to account for the tie (e.g., 1, 2, 2, 4).

Rules:

  • Rank must be calculated based on the score in descending order.
  • Use the RANK() logic (with gaps).
  • Output columns: user_id, score, rank.
  • Results must be sorted by rank in ascending order.
Tests your understanding of
Window Functions, Ranking and Sorting

Input Tables

Scores
user_id(INTEGER)score(DECIMAL)
14.5
24.5
33.85
44
55
User_Profiles
user_id(INTEGER)username(VARCHAR)
1meta_dev
5zuck
Activity_Logs
log_id(INTEGER)user_id(INTEGER)last_login(TIMESTAMP)
100112026-02-09 12:00:00

Expected Output

user_id(INTEGER)score(DECIMAL)rank(INTEGER)
551
14.52
24.52
444
33.855

Tags

MediumASKED IN INTERVIEWWindow FunctionsRankingSorting
20-25 min
58%

Hints