Return the unique values that appear in one array but not the other, in both directions.
You are given two integer arrays nums1 and nums2. Return the difference between the two arrays as two lists:
nums1 but do not appear in nums2.nums2 but do not appear in nums1.The order of values inside each list does not matter.
Compute the two set differences efficiently by identifying which values are present in each array and filtering out common values.
nums1: an array of integersnums2: an array of integersReturn a list of two lists:
answer[0]: distinct integers in nums1 but not in nums2answer[1]: distinct integers in nums2 but not in nums11 <= nums1.length, nums2.length <= 1000-1000 <= nums1[i], nums2[i] <= 1000Example 1
Input
nums1 = [1,2,3], nums2 = [2,4,6]
Output
[[1,3],[4,6]]
Explanation
Values 1 and 3 are only in the first array, while 4 and 6 are only in the second array.
Example 2
Input
nums1 = [1,2,3,3], nums2 = [1,1,2,2]
Output
[[3],[]]
Explanation
After removing duplicates, only 3 is exclusive to nums1; every value in nums2 also appears in nums1.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.