Problem 357546 · easy · Phase 03 Linear Management & Searching

Elements in Exactly One Sorted List

two pointers · sorted arrays · merging

Given two lists of distinct integers a and b, each sorted in increasing order, return a sorted list of the values that appear in exactly one of them.

Examples

Input:  a = [1, 3, 5, 7], b = [3, 4, 7, 9]
Output: [1, 4, 5, 9]

Input:  a = [2, 4], b = [2, 4]
Output: []

Constraints

  • 0 <= len(a), len(b) <= 10**5
  • Target: O(len(a) + len(b)) time, O(1) extra space beyond the output; no sets.

Goals

  • Handle three cases per step: smaller in a, smaller in b, equal
  • Flush the remainder of whichever list is left
Starting Python…