Given an integer array nums, return an array result of the same length where result[i] is the number of times nums[i] has appeared in nums from index 0 up to and including index i.
In other words, result[i] is the running occurrence count of the value nums[i] at position i.
Function Signature
def running_frequency(nums: list[int]) -> list[int]:
...
Constraints
-
1 <= len(nums) <= 10^5
-
-10^9 <= nums[i] <= 10^9
Examples
Input: nums = [1,2,1,3,2,1]
Output: [1,1,2,1,2,3]
At each index: 1 appears for the 1st time, 2 appears for the 1st time, 1 appears for the 2nd time, 3 appears for the 1st time, 2 appears for the 2nd time, and 1 appears for the 3rd time.
Input: nums = [5,5,5,5]
Output: [1,2,3,4]
5 occurs for the 1st, 2nd, 3rd and 4th time at the four positions.
Input: nums = [-1,0,-1,0,0]
Output: [1,1,2,2,3]
Negative values and zero are counted like any other value. The second -1 is its 2nd occurrence, and the three zeros get 1, 2 and 3.