Problem 281822 · easy · Level 02 Linear Data Structures

First Unique Ticket

hash maps · counting · two passes

Raffle tickets are drawn from a bowl and their numbers are recorded in tickets, in draw order. A number that was drawn exactly once wins. Return the winning number that appears earliest in the list. If every number was drawn more than once (or the list is empty), return -1.

Examples

Input:  tickets = [4, 5, 4, 6]
Output: 5
Explanation: 4 appears twice; 5 and 6 appear once, and 5 comes first.

Input:  tickets = [1, 1]
Output: -1

Constraints

  • 0 <= len(tickets) <= 10**5
  • -10**9 <= tickets[i] <= 10**9
  • Target complexity: O(n) time, O(n) extra space.

Goals

  • Count first, then scan in original order
  • Distinguish 'first in the list' from 'first in the dict'
Starting Python…