Math Fundamentals18 sections · 814 units
Open in Course

Problem - Find Difference

LeetCode 2215

Given two arrays nums1\text{nums1} and nums2\text{nums2}, return a list [answer1,answer2][\text{answer1}, \text{answer2}] where answer1\text{answer1} contains all distinct integers in nums1\text{nums1} but not in nums2\text{nums2}, and answer2\text{answer2} contains all distinct integers in nums2\text{nums2} but not in nums1\text{nums1}.

For example, if nums1=[1,2,3]\text{nums1} = [1, 2, 3] and nums2=[2,4,6]\text{nums2} = [2, 4, 6], then answer1=[1,3]\text{answer1} = [1, 3] and answer2=[4,6]\text{answer2} = [4, 6].

This is the set difference operation applied twice. Try solving it before reading on.