FunctionRacerProblemsRace

Hands That Hit the Target

MediumDynamic programmingPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Dynamic programming problems