Hash map · Easy
A monitoring report needs the number of event types occurring often enough to investigate. Repeated deliveries contribute to a type’s frequency, but the report counts each qualifying type once rather than counting its occurrences.
Return the number of distinct event values whose total frequency is at least k.
Input
Call
- Implement solve(input) and return the result. The provided adapter handles JSON input and output.
Input shape
{ nums: integer[], k: integer }
Fields
- nums is an array of signed integers in its original order. Equal values at different indexes are separate entries.
- k is the positive minimum frequency required for a value to qualify.
Output
Return value
- Return a count of distinct values, not occurrences. Equality with k qualifies.
- Return 0 for an empty input or when no frequency reaches k.
Constraints
- 0 <= nums.length <= 100000; -1000000000 <= nums[i] <= 1000000000.
- All requested totals and counts fit exactly in a safe JSON integer.
- 1 <= k <= 100001.
Examples
Example 1
{
"k": 2,
"nums": [
2,
2,
2,
5,
5,
8
]
}Returns
2Example 2
{
"k": 2,
"nums": [
4,
4,
4
]
}Returns
1Required complexity
O(n) expected time and O(u) space for u distinct values