Count Distinct Values (Set 1)

Easy

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

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

Example 1

countDistinctValues()
Input
nums = [6, 7, 3]
Output
3

Why

`countDistinctValues` returns `3` for this input.

Example 2

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

Why

`countDistinctValues` returns `4` 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.