Show problems as
Classic problem #645EasyArrayHash TableBit ManipulationSorting

Set Mismatch

Real-world version: Bib Number Mixup
Tracked in this browser only
Read Set Mismatch on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A road race orders one bib per runner, so a field of n runners should receive the numbers 1 through n, each on a single bib. The press misfired: one number came out on two bibs and one number never came out at all. Every other number landed on exactly one bib.

You are given the integer array bibs of length n holding the number printed on each bib, in the order the bibs came off the press. Return a two-element array [repeated, absent], where repeated is the number printed on two bibs and absent is the number in the range 1 to n printed on none of them.

Examples

Example 1

Input
bibs = [3, 1, 3]
Output
[3, 2]

Three bibs came off the press for a field of 3 runners. The number 3 sits on two of them and no bib carries 2, so the answer is [3, 2].

Example 2

Input
bibs = [5, 3, 2, 1, 2]
Output
[2, 4]

Two bibs carry the number 2 and no bib carries 4.

Example 3

Input
bibs = [1, 2, 3, 5, 5, 6]
Output
[5, 4]

The number 5 appears on two bibs, and 4 is the number in the range 1 to 6 that is missing.

Constraints

  • 2 <= bibs.length <= 10^4
  • 1 <= bibs[i] <= 10^4
  • Exactly one number in the range 1 to bibs.length appears twice in bibs
  • Exactly one number in the range 1 to bibs.length does not appear in bibs
  • Every other number in the range 1 to bibs.length appears exactly once

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def find_bib_slip(bibs: list[int]) -> list[int]:
Java
public int[] findBibSlip(int[] bibs)