Hands That Hit the Target
Each card in cards carries a point value. A hand is any selection of cards from the list, each card used at most once; two cards with the same value are still different cards, so selecting one or the other gives different hands. Return the number of hands whose point values add up to exactly target. The empty hand has a total of 0, so it counts when target = 0.
Example 1
cards [2,3,5,7]
target 10
returns 2
The hands are 3 + 7 and 2 + 3 + 5.
Example 2
cards [1,1,2]
target 2
returns 2
The two 1s together make 2, and so does the 2 alone.
Constraints
0 <= len(cards) <= 201 <= cards[i] <= 500 <= target <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Dynamic programming problems
- Keystrokes to TransformMedium
- Knight on the KeypadMedium
- Letter DecodingsMedium
- Lightest Deletions to MatchMedium
- Longest Climbing ChainMedium
- Longest Insertion LadderMedium
- Longest Mirror SubsequenceMedium
- Loot Around the Lantern RingMedium