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!

How 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 July 2026

Contest runs July 1 - 31. Complete challenges to climb the leaderboard!

Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In