Back to DSA sheet

Find the Difference of Two Arrays

EasyArrays

Given two arrays, return two lists: the distinct values present in the first but not the second, and the distinct values present in the second but not the first.

Input format (stdin): line 1 has n1 then n1 integers; the next line has n2 then n2 integers. Output two lines: the first list (ascending) and the second list (ascending). A list with no values is a blank line.

Examples
Input: 3 1 2 3 3 2 4 6
Output: 1 3 4 6
1,3 are only in the first; 4,6 only in the second.
Constraints
  • 1 <= n1, n2 <= 1000
  • -1000 <= values <= 1000
Sheets
NeetCode 250
find-the-difference-of-two-arrays.cpp2 sample tests
Loading editor
Test results

Run the sample tests to check your solution against expected output.

Custom input (stdin)
Output

Run your code to see its output.