Problem 290602 · easy · Phase 02 Linear Data Structures

Missing Badges

sets · iteration

Badges are numbered 1 to n. The list seen records the badges that were scanned today (a badge may be scanned several times). Return a sorted list of badge numbers that were never scanned.

Examples

Input:  n = 6, seen = [2, 5, 2, 1]
Output: [3, 4, 6]

Input:  n = 3, seen = [1, 2, 3, 3]
Output: []

Constraints

  • 0 <= n <= 10**5, 1 <= seen[i] <= n
  • Target complexity: O(n + len(seen)) time.

Goals

  • Build a set for O(1) membership
  • Produce a sorted result by iterating a range, not by sorting
Starting Python…