Given an array of integers nums, return how many distinct values it contains.
Count Distinct Values (Set 2) — the data. This set runs 4 cases: nums holds arrays of 10–17 items, with values from 1 to 8. The hidden cases are the largest of the set.
Example 1
countDistinctValues()
Input
nums =[2,2,5,4,8,6,1,4,1,3,1,8,5,5,7]
Output
8
Why
`countDistinctValues` returns `8`forthisinput.
Example 2
countDistinctValues()
Input
nums =[3,4,2,1,8,2,8,5,2,1,8,4,8,6,1]
Output
7
Why
`countDistinctValues` returns `7`forthisinput.
Constraints
0<=nums.length<=10^5-10^4<= nums[i]<=10^4
Every caseinthisset 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.