Find the Difference of Two Arrays

EasyArrays & Hashinghashing

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

Given two integer arrays nums1 and nums2, return a list answer of exactly two lists: - answer[0] holds the **distinct** values that appear in nums1 but not in nums2. - answer[1] holds the **distinct** values that appear in nums2 but not in nums1. Each inner list must be sorted in ascending order. An inner list is empty when there are no such values.

Examples

Input: nums1 = [1,2,3], nums2 = [2,4,6]
Output: [[1,3],[4,6]]
1 and 3 are missing from nums2; 4 and 6 are missing from nums1.
Input: nums1 = [1,2,3,3], nums2 = [1,1,2,2]
Output: [[3],[]]
3 appears only in nums1 and is listed once. Every value of nums2 is in nums1.

Constraints

  • 1 <= nums1.length, nums2.length <= 1000
  • -1000 <= nums1[i], nums2[i] <= 1000

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More hashing problems