dsa · easy

Find the Difference of Two Arrays

You are given two integer arrays nums1 and nums2. Return a list of two lists: the first holds every distinct integer that appears in nums1 but not in nums2, and the second holds every distinct integer that appears in nums2 but not in nums1. Duplicates within an input array count once. Order within each output list does not matter.

Arguments

Example

nums1 = [1,2,3], nums2 = [2,4,6]

Only 1 and 3 appear in nums1 but not nums2; only 4 and 6 appear in nums2 but not nums1 → [[1,3],[4,6]].

nums1 = [1,2,3,3], nums2 = [1,1,2,2] → the repeated 3 appears in nums1 only; nothing in nums2 is missing from nums1 → [[3],[]].

Constraints

1 <= nums1.length, nums2.length <= 1000 -10^6 <= nums1[i], nums2[j] <= 10^6 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[1,2,3]
[2,4,6]

Expected:
[[1,3],[4,6]]

Example 2

Input:
[1,2,3,3]
[1,1,2,2]

Expected:
[[3],[]]

Example 3

Input:
[1,2]
[3,4]

Expected:
[[1,2],[3,4]]

Open in the Dojo editor