Skip to main content

Practice · 3 of 5

Count Distinct Values

CHALLENGE
Difficulty: beginner+25 XP

**Description:** Given n numbers, print how many **distinct** values appear. **Input:** Line 1: n (1 ≤ n ≤ 10^5). Line 2: n integers (−10^9 ≤ each ≤ 10^9). **Output:** One integer. **Example:** 6 / 2 7 2 9 7 2 → 3 (values 2, 7, 9). *Hint:* sort, then count positions where a[i] != a[i-1].

Back to lesson: Practice: Array Mechanics Set