Repeated Number Sum
Given an array of integers, calculate the sum of numbers that occur more than once in the array. It is guaranteed that the array will contain at least two integers.
[ 2, 3, 2, 6, 7, 3 ]
Explanation. The numbers 2 and 3 appear more than once. Sum of all occurrences: 2+2+3+3 = 10.
[ 1, 1, 1, 2, 3 ]
Explanation. Only the number 1 appears more than once. Sum of all occurrences: 1+1+1 = 3.
[ 10, 20, 20, 10, 10 ]
Explanation. The numbers 10 and 20 appear more than once. Sum of all occurrences: 10+10+10+20+20 = 70.
[ 5, 9, 5, 5, 9, 8 ]
Explanation. The numbers 5 and 9 appear more than once. Sum of all occurrences: 5+5+5+9+9 = 33.
Follow-up: What modifications would you make to this function if the input sizes could be significantly large?
1. All inputs will be integers.\n2. The array will have at least two elements.
- Views
- 3