Given two Sets of integers, return the symmetric difference (elements that are in either set but not in both). The result should be a new Set. Return null if either input is null.
Examples:
Input: set1 = {1, 2, 3}, set2 = {2, 3, 4}
Output: {1, 4}
Explanation: 1 is only in set1, 4 is only in set2. Elements 2 and 3 are in both sets so they are excluded.
Input: set1 = {1, 2}, set2 = {3, 4}
Output: {1, 2, 3, 4}
Explanation: No common elements, so all elements are in the symmetric difference.
Input: set1 = {1, 2}, set2 = {1, 2}
Output: {}
Explanation: Both sets contain the same elements, so the symmetric difference is empty.
Input: set1 = null, set2 = {1, 2}
Output: null
Explanation: Null input returns null.
Apex Code Editor
Welcome to Lightning Challenge!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay Feb 2026
Contest runs February 1 - 28. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.