← 返回 waymo 的题目列表Count Frequencies in a Bounded Integer Array
类型:online_judge
Given an integer array nums of length n. Every element is an unsigned 16-bit integer:
0 <= nums[i] < 2^16.
Count the occurrences of every present integer and output the value-frequency pairs in ascending order of value.
Requirements:
Do not use a hash table.
You may use the fact that the value range is fixed and bounded by 2^16 - 1.
In C++, the input may be provided as a pointer to the first element plus a length, rather than as a vector.
Input Format
First line: integer n
Second line: n integers nums[i]
Output Format
For each value that occurs in the input, print one line:
value count
Example
Input:
8
5 1 5 65535 1 0 5 65535
Output:
0 1
1 2
5 3
65535 2
Constraints
0 <= n <= 10^6
0 <= nums[i] < 65536
Example
Input
8
5 1 5 65535 1 0 5 65535
Output
0 1
1 2
5 3
65535 2