Count Repeated Values (Set 9)

Easy

Given an array of integers nums, return how many distinct values appear more than once.

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

Example 1

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

Why

`countDuplicatedValues` returns `6` for this input.

Example 2

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

Why

`countDuplicatedValues` returns `6` 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

ArraysCounting

Implement countDuplicatedValues in the editor and return the answer — printing it is never graded.