Ezvor

1230. Toss Strange Coins

MediumArray Preparing judge… LeetCode
ArrayMathDynamic ProgrammingProbability and Statistics

Hints

Hint 1
What about solving the problem with DP?
Hint 2
Use DP with two states dp[pos][cnt], where pos represents the pos-th coin and cnt is the number of heads seen so far.
Hint 3
You can do the transitions with a little bit math.
Hint 4
For the base case, when pos == n return (cnt == target) to filter out the invalid scenarios.