Problem 276418 · easy · Phase 02 Linear Data Structures

Only in the First List

sets · difference · ordering

Given two lists of integers a and b, return the values that occur in a but not in b. Keep the order in which they first appear in a and list each value once.

Examples

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

Constraints

  • 0 <= len(a), len(b) <= 10**5
  • Target complexity: O(n + m) time.

Goals

  • Compute a set difference while keeping list order
  • Remove duplicates without sorting
Starting Python…