Create a method that performs various operations on two sets of integers and returns the results in a map. The operations to implement are:
- Union - all elements that are in either set
- Intersection - only elements that are in both sets
- Difference - elements that are in the first set but not in the second
- Symmetric Difference - elements that are in either set but not in both
Examples:
Input: set1 = {1, 2, 3}, set2 = {3, 4, 5}
Output: {
'union' => {1, 2, 3, 4, 5},
'intersection' => {3},
'difference' => {1, 2},
'symmetricDifference' => {1, 2, 4, 5}
}
Input: set1 = {10, 20, 30}, set2 = {40, 50, 60}
Output: {
'union' => {10, 20, 30, 40, 50, 60},
'intersection' => {},
'difference' => {10, 20, 30},
'symmetricDifference' => {10, 20, 30, 40, 50, 60}
}
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.