Skip to the code
cf.
+25 XP

#72 Double-Booked and Empty Seat

medium

A seating app assigned seats 1 to n to n guests, but a bug gave one seat to two guests, so one seat was left empty. The assigned seat numbers are in seats.

Write seatMismatch(seats) that returns [doubleBooked, empty].

Example 1

Input: seats = [3,1,3,4,5]
Output: [3,2]

Seat 3 was given out twice and seat 2 to nobody.

Example 2

Input: seats = [1,1]
Output: [1,2]

Seat 1 was given to both guests.

Constraints

  • 2 <= seats.length <= 10^5
  • 1 <= seats[i] <= seats.length
  • Exactly one seat appears twice and exactly one is missing.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).