Problem · Array
Fixed-Range Frequency Count
Learn this problemProblem statement
Given an array of integers, count how many times each value appears. Every value is in the fixed domain from 0 through 65535, inclusive.
Use a direct frequency array indexed by the input value. Return only values with positive frequency as strings value|count, ordered by numeric value in ascending order.
Function
countFixedRangeFrequencies(values: int[]) → String[]Examples
Example 1
values = [2,65535,2,0,65535,2]return = ["0|1","2|3","65535|2"]The value 0 appears once, 2 appears three times, and the largest domain value appears twice.
Example 2
values = [5,4,5,4,3]return = ["3|1","4|2","5|2"]Results are emitted in numeric value order regardless of the first occurrence order.
Constraints
0 <= values.length <= 200000.0 <= values[i] < 65536.- Every frequency fits in a signed 32-bit integer.