Ctrl K

Fewest Guests by Lanyard Color

Medium
At a conference every guest wears a badge lanyard of some color. The organizers asked several guests: "How many other people here wear a lanyard of the same color as yours?" Everyone answered truthfully, and the answers are in the array replies. Not everyone was asked, so the real number of guests is unknown. Return the smallest number of guests consistent with all the answers.
Example 1
replies=[2, 2, 2, 2] → 6

A reply of 2 means three people wear that color. Four such guests cannot fit in one group of three, so there are two colors of three guests each, 6 in total.

Example 2
replies=[0, 1, 0] → 4

Each guest who said 0 is alone in their color, that is 2 guests. The one who said 1 shares a color with one more guest who was not asked. That makes 4.

Constraints
  • 1 ≤ replies.length ≤ 1000
  • 0 ≤ replies[i] < 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsLargest MEX After Shifts MediumVertical Mirror Line MediumEquidistant Point Triples MediumA Stretch Divisible by k MediumJobs With a Cooldown Medium
loading Python…
Input
replies=[2, 2, 2, 2]
Expected
6

Run checks the first 3 tests in your browser. Submit checks all 68 tests on the server, hidden ones included.