Ctrl K

All Distinct Card Hands

Medium
You hold cards with numbers cards, and some numbers may repeat. A hand is any selection of these cards, including none of them or all of them. Two hands that differ only in card order, or in which of several equal cards was picked, count as the same hand. Return all distinct hands. Each hand is a list of numbers; neither the order of the hands nor the order of numbers inside a hand matters.
Example 1
cards=[3, 1, 3] → [[1, 3, 3], [1, 3], [1], [3, 3], [3], []]

The two 3s look the same, so the hand [1, 3] appears only once. There are six hands: [], [1], [3], [1, 3], [3, 3], [1, 3, 3].

Example 2
cards=[-2, -2] → [[-2, -2], [-2], []]

You can take nothing, one -2, or both.

Constraints
  • 1 ≤ len(cards) ≤ 10
  • -10 ≤ cards[i] ≤ 10
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsEvery Topping Combo MediumSquare Frame From Sticks MediumAll Non-Falling Subsequences MediumSeating by Divisibility MediumCheapest Basket with Bundles Medium
loading Python…
Input
cards=[3, 1, 3]
Expected
[[1, 3, 3], [1, 3], [1], [3, 3], [3], []]

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