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.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.
cards=[3, 1, 3] → False
The top card is 3, so a 2 is also needed, and it is missing.
cards=[1, 1] → True
A deck whose top card is 1, taken twice, fits the rule.
cards=[2, 4, 1, 4, 3]
True
Run checks the first 3 tests in your browser. Submit checks all 114 tests on the server, hidden ones included.