Compute an Exact Head Count Probability with Dynamic Programming

Read the full interview experience this question came from →

Quick Overview

Compute the probability of exactly five heads in ten tosses of a coin with heads probability 0.7. Derive a dynamic program, implement safe state updates, and verify the result with the binomial formula.

Compute an Exact Head Count Probability with Dynamic Programming

Company: Akuna Capital

Role: Quantitative Researcher

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

A biased coin has probability 0.7 of heads and 0.3 of tails on each independent toss. Compute the probability of exactly five heads in ten tosses, then implement a dynamic-programming calculation rather than enumerating every sequence. ### Constraints and Clarifications The report recalls the ten-toss, five-head instance. For a reusable practice interface, define probabilityExactly(n, h, p), where n is a nonnegative integer, h is an integer, and 0 <= p <= 1 is the identical independent probability of heads on each toss. Return zero if h is outside [0,n]. This parameterization is interface normalization; no additional numerical size limits were reported. Return a numerical probability, not a sampled outcome. Evaluate the reported instance with n=10, h=5, p=0.7. As a practice comparison convention for that instance, accept absolute error at most 1e-9; this is not a reported interview requirement or a guarantee for an unbounded generalized domain. ### What a Strong Answer Covers Define the DP state and base case, derive both transitions, keep updates inside the correct loop, and give time and space complexity. Check the reported instance against the binomial formula and cover zero tosses and deterministic coins. ### Follow-up Questions - How can the DP use only O(h) space without overwriting states needed for the same toss? - What changes if the probability of heads differs on every toss?

Overview: Compute the probability of exactly five heads in ten tosses of a coin with heads probability 0.7. Derive a dynamic program, implement safe state updates, and verify the result with the binomial formula.

Read the full Akuna Capital Quantitative Researcher interview experience this question came from

Akuna Capital logo
Akuna Capital
Aug 30, 2026
mediumQuantitative ResearcherTechnical ScreenCoding & Algorithms
0
0

A biased coin has probability 0.7 of heads and 0.3 of tails on each independent toss. Compute the probability of exactly five heads in ten tosses, then implement a dynamic-programming calculation rather than enumerating every sequence.

Constraints and Clarifications

The report recalls the ten-toss, five-head instance. For a reusable practice interface, define probabilityExactly(n, h, p), where n is a nonnegative integer, h is an integer, and 0 <= p <= 1 is the identical independent probability of heads on each toss. Return zero if h is outside [0,n]. This parameterization is interface normalization; no additional numerical size limits were reported. Return a numerical probability, not a sampled outcome. Evaluate the reported instance with n=10, h=5, p=0.7. As a practice comparison convention for that instance, accept absolute error at most 1e-9; this is not a reported interview requirement or a guarantee for an unbounded generalized domain.

What a Strong Answer Covers Guidance

Define the DP state and base case, derive both transitions, keep updates inside the correct loop, and give time and space complexity. Check the reported instance against the binomial formula and cover zero tosses and deterministic coins.

Follow-up Questions Guidance

  • How can the DP use only O(h) space without overwriting states needed for the same toss?
  • What changes if the probability of heads differs on every toss?