Ctrl K

Deck With a Doubled Top Card

Easy
A game uses decks of a special kind: for some n ≥ 1, the deck holds one card of each number from 1 to n - 1 and two cards numbered n, so n + 1 cards in total. For example, with n = 1 the deck is [1, 1], and with n = 4 it is [1, 2, 3, 4, 4]. You are handed a pile cards in arbitrary order. Return True if it can be rearranged into such a deck for some n, and False otherwise.
Example 1
cards=[2, 4, 1, 4, 3] → True

The top card is 4. A full deck is 1, 2, 3 once each plus two 4s, and that is exactly what we have, just shuffled.

Example 2
cards=[3, 1, 3] → False

The top card is 3, so a 2 is also needed, and it is missing.

Example 3
cards=[1, 1] → True

A deck whose top card is 1, taken twice, fits the rule.

Constraints
  • 1 ≤ len(cards) ≤ 100
  • 1 ≤ cards[i] ≤ 200
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Candidate With Most Votes EasyDoes Any Value Repeat EasyThe Lost Ticket EasyValues in Both Lists EasyShared Values With Repeats Easy
loading Python…
Input
cards=[2, 4, 1, 4, 3]
Expected
True

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