EasyPythonJavaScriptTypeScript
Sets — Set Operations
PythonSetsData Types
Implement solve(a, b, op) where a and b are lists of values and op is one of:
"union"→ elements inaorb(or both)"intersection"→ elements in bothaandb"difference"→ elements inabut not inb"symmetric_difference"→ elements inaorbbut not both
Return the result as a sorted list (so the output is deterministic).
Examples
solve([1,2,3], [2,3,4], "union")→[1, 2, 3, 4]solve([1,2,3], [2,3,4], "intersection")→[2, 3]solve([1,2,3], [2,3,4], "difference")→[1]solve([1,2,3], [2,3,4], "symmetric_difference")→[1, 4]
Sample tests
Test #1Symmetric difference
Input: [[1,2,3],[2,3,4],"symmetric_difference"]
Output: [1,4]
Test #2Union
Input: [[1,2,3],[2,3,4],"union"]
Output: [1,2,3,4]
Test #3Intersection
Input: [[1,2,3],[2,3,4],"intersection"]
Output: [2,3]
Test #4Difference
Input: [[1,2,3],[2,3,4],"difference"]
Output: [1]