Count Distinct Values (Set 5)

Easy

Given an array of integers nums, return how many distinct values it contains.

Count Distinct Values (Set 5) — the data. This set runs 4 cases: nums holds arrays of 20–39 items, with values from 1 to 8. The hidden cases are the largest of the set.

Example 1

countDistinctValues()
Input
nums = [5, 8, 7, 5, 8, 3, 5, 7, 4, 4, 5, 2, 2, 1, 5, 6, 8, 3, 3, 2, 6, 8, 3, 3, 3, 8, 3, 8, 6, 4, 3, 4, 4, 1, 5, 3, 2, 2, 1]
Output
8

Why

`countDistinctValues` returns `8` for this input.

Example 2

countDistinctValues()
Input
nums = [2, 8, 6, 1, 7, 7, 2, 1, 2, 4, 8, 5, 4, 5, 8, 8, 3, 5, 5, 2]
Output
8

Why

`countDistinctValues` returns `8` for this input.
Constraints
0 <= nums.length <= 10^5
-10^4 <= nums[i] <= 10^4
Every case in this set must pass: the first two are visible on Run, the last two unlock on Submit.

Topics

ArraysHash Table

Implement countDistinctValues in the editor and return the answer — printing it is never graded.