Count Distinct Values (Set 6)

Easy

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

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

Example 1

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

Why

`countDistinctValues` returns `7` for this input.

Example 2

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