Zepruv › Coding problems

X of a Kind in a Deck of Cards

Easy · Array, Hash Table, Math, Counting, Number Theory

You are given an integer array deck where deck[i] represents the number written on the ith card.
Partition the cards into one or more groups such that:
Return true if such partition is possible, or false otherwise.

Example 1

Input: deck = [1,2,3,4,4,3,2,1]
Output: true

Possible partition [1,1],[2,2],[3,3],[4,4].

Example 2

Input: deck = [1,1,1,2,2,2,3,3]
Output: false

No possible partition.

Constraints

Starter code (python)

class Solution(object):
    def hasGroupsSizeX(self, deck):
        """
        :type deck: List[int]
        :rtype: bool
        """
        

Related problems

Previous: Snakes and Ladders · Next: Partition Array into Disjoint Intervals · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.