All problems
0221EasyArrayHash TableBit ManipulationSorting

Bib Number Mixup

Tracked in this browser only
Write code

Trains the technique from

LeetCode 645Set Mismatch

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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