Tally Occurrences

EasyData EngineeringHash TableArray

Description

Given an array of integers nums, return an object mapping each distinct value (as a key) to how many times it occurs.

Examples

Input:nums = [1,1,2,3,3,3]
Output:{"1":2,"2":1,"3":3}
Explanation:

Counting how often each value appears yields {"1":2,"2":1,"3":3}.

Input:nums = [5]
Output:{"5":1}
Explanation:

Counting how often each value appears yields {"5":1}.

Input:nums = [2,2,2,2]
Output:{"2":4}
Explanation:

Counting how often each value appears yields {"2":4}.

Constraints

  • 1 ≤ nums.length ≤ 10⁴

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.