Sum of Unique Elements
Given an array of integers, calculate the sum of all the unique integers in the array. An integer is considered unique if it appears exactly once in the array.
[ [ 4, 4, 5, 6, 7, 7 ] ]
Explanation. 5 and 6 are unique integers in the array. Their sum is 11.
[ [ 1, 2, 3, 2 ] ]
Explanation. 1 and 3 are unique integers in the array. Their sum is 4.
[ [ -1, -1, -2, 3, 4 ] ]
Explanation. -2, 3, and 4 are unique integers in the array. Their sum is 5.
[ [ 100, 200, 100, 300 ] ]
Explanation. 200 and 300 are unique integers in the array. Their sum is 500.
[ [ 7 ] ]
Explanation. 7 is the only integer in the array and is unique by default. The sum is 7.
Follow-up: Can you solve the problem in linear time complexity?
1. The array will contain at least one element.\n2. All elements are integers from -1000 to 1000.
- Views
- 3