#3712
Sum of Elements With Frequency Divisible by K
easy · 77.6% accepted · 54 likes · top 89%
array · hash table · counting
Description
You are given an integer array nums and an integer k.
Return an integer denoting the sum of all elements in nums whose frequency is divisible by k, or 0 if there are no such elements.
Note: An element is included in the sum exactly as many times as it appears in the array if its total frequency is divisible by k.
Solution