Skip to main content

Practice · 4 of 5

Ranks

CHALLENGE
Difficulty: intermediate+25 XP

**Description:** For each of n values, print its **dense rank**: the position of its value in the ascending order of DISTINCT values (1-based). Equal values share the same rank; ranks are consecutive. **Input:** Line 1: n (1 <= n <= 10^5). Line 2: n integers (|a_i| <= 10^9). **Output:** n integers — the ranks in input order. **Example:** 4 / 30 10 20 10 -> 3 1 2 1 (distinct: 10 20 30).

Back to lesson: Practice: Sorting Set