X of a Kind in a Deck of Cards

You are given an integer array deck where deck[i] represents the number written on the i^th card.

Partition the cards into one or more groups such that:

  • Each group has exactly x cards where x > 1.
  • All the cards in one group have the same integer written on them.

Return true if such partition is possible, or false otherwise.

Example 1
Inputdeck = [1,2,3,4,4,3,2,1]
Outputtrue
Possible partition [1,1],[2,2],[3,3],[4,4].
Example 2
Inputdeck = [1,1,1,2,2,2,3,3]
Outputfalse
No possible partition.

Constraints

  • 1 <= deck.length <= 10^4
  • 0 <= deck[i] < 10^4

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate