Frequency of Every Integer Value
Problem statement
Given an integer array nums, count how many times each different value occurs.
For this exercise, assume every input occurrence contributes one to that value's frequency. Return the complete frequency table as rows [value,count], one row per observed value, in increasing numeric value order. Empty input returns an empty matrix. Do not modify the input.
Function
countFrequencies(nums: int[]) → int[][]Examples
Example 1
nums = [3,1,3,-2,1,3]return = [[-2,1],[1,2],[3,3]]Each different integer gets one row with its occurrence count, ordered by value.
Example 2
nums = [7,7,7]return = [[7,3]]Equal values belong to one category whose frequency is three.
Example 3
nums = []return = []An empty input has no observed categories.
Constraints
- For this exercise, assume
0 <= nums.length <= 1000. - For this exercise, assume each value is an integer from
-1000000through1000000.