Count Distinct Values (Set 3)

Easy

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

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

Example 1

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

Why

`countDistinctValues` returns `7` for this input.

Example 2

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