As reported: JPMorgan Chase Java / Spring Boot engineer (Hyderabad, June 2025), round 1 (technical, Java + Spring Boot), coding part: merge two arrays keeping only the unique, non-common elements, using Java Streams.
Given two integer arrays a and b, return the values that appear in exactly one of the two arrays, each value once. In Java, write it with the Streams API.
Example 1
a = [1,2,3,4], b = [3,4,5,6] -> [1,2,5,6]
Example 2
a = [7,7,1], b = [1,9,9] -> [7,9] duplicates inside one array still count once
Clarifications
- A value present in both arrays is left out entirely, however many times it appears.
- The result may be in any order; the code runner sorts it before comparing.
Constraints: 0 ≤ a.length, b.length ≤ 10^5; -10^9 ≤ a[i], b[i] ≤ 10^9.
Code runner format: two lines — a and b as JSON arrays. Implement mergeUnique(a, b); the harness sorts the returned values and prints them as a JSON array.