Sum of Unique Elements - Problem
You are given an integer array nums. The unique elements of an array are the elements that appear exactly once in the array.
Return the sum of all the unique elements of nums.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [1,2,3,2]
›
Output:
4
💡 Note:
Elements 1 and 3 appear exactly once, so sum = 1 + 3 = 4. Element 2 appears twice so it's not unique.
Example 2 — All Unique
$
Input:
nums = [1,2,3,4,5]
›
Output:
15
💡 Note:
All elements appear exactly once, so sum = 1 + 2 + 3 + 4 + 5 = 15
Example 3 — No Unique Elements
$
Input:
nums = [1,1,2,2,3,3]
›
Output:
0
💡 Note:
Every element appears exactly twice, so no element is unique. Sum = 0
Constraints
- 1 ≤ nums.length ≤ 100
- -100 ≤ nums[i] ≤ 100
Visualization
Tap to expand
Understanding the Visualization
1
Input Array
Array with some duplicate elements
2
Find Unique
Identify elements appearing exactly once
3
Sum Result
Add up all unique elements
Key Takeaway
🎯 Key Insight: Only elements appearing exactly once contribute to the final sum
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code