Hash map · Easy
A diagnostic report groups integer event codes by how often they appear. The report must be stable across repeated runs and easy to compare, so groups are ordered numerically rather than by first appearance or string order.
Return one value and count pair for every distinct event code in ascending numeric order.
Input
Call
- Implement solve(input) and return the result. The provided adapter handles JSON input and output.
Input shape
{ nums: integer[] }
Fields
- nums is an array of signed integers in its original order. Equal values at different indexes are separate entries.
Output
Return value
- Return [[value,count], ...] with each distinct value once. Counts are positive.
- Sort by numeric value, not count or string representation. Empty input returns [].
Constraints
- 0 <= nums.length <= 100000; -1000000000 <= nums[i] <= 1000000000.
- All requested totals and counts fit exactly in a safe JSON integer.
Examples
Example 1
{
"nums": [
10,
2,
10,
-1
]
}Returns
[
[
-1,
1
],
[
2,
1
],
[
10,
2
]
]Example 2
{
"nums": [
0,
0
]
}Returns
[
[
0,
2
]
]Required complexity
O(n + u log(u + 1)) time and O(u) space for u distinct values