Count Distinct Values (Set 10)

Easy

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

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

Example 1

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

Why

`countDistinctValues` returns `8` for this input.

Example 2

countDistinctValues()
Input
nums = [6, 3, 1, 1, 6, 2, 2, 3, 6, 7, 8, 7, 3, 5, 2, 6, 3, 7, 6, 7, 3, 6, 2, 7, 6, 8, 8, 2, 6, 2, 4, 6, 4, 6, 2, 1, 6, 7, 1, 8, 4, 1, 5, 7, 4]
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.