Find the Difference of Two Arrays
Easy
122
6
48.2% Acceptance
In this lab, you have to implement a function findDifference
that will take two 0-indexed integer arrays nums1
and nums2
. You should return a list answer
of size 2 where:
answer[0]
is a list of all distinct integers innums1
which are not present innums2
.answer[1]
is a list of all distinct integers innums2
which are not present innums1
.
The integers in the lists may be returned in any order.
Examples
Here are some examples of the findDifference
function:
findDifference([1,2,3], [2,4,6]); // Output: [[1,3],[4,6]] findDifference([1,2,3,3], [1,1,2,2]); // Output: [[3],[]]
Explanation
- For the first example, 2 is present in both arrays but 1 and 3 are not present in
nums2
, soanswer[0]
is [1,3]; Similarly, 4 and 6 are not present innums1
, soanswer[1]
is [4,6]. - For the second example, 1 and 2 are present in both arrays, but 3 is not present in
nums2
soanswer[0]
is [3]; All integers innums2
are present innums1
, soanswer[1]
is [].
Constraints
1 <= nums1.length, nums2.length <= 1000
-1000 <= nums1[i], nums2[i] <= 1000
Challenges
In order to successfully complete this lab, you must pass the following challenges:
- Implement the
findDifference
function and make sure it returns the correct difference between the two arraysnums1
andnums2
. - Export the
findDifference
function using the ESM export syntax.