Longest Run of Heads

Python for AIMedium+10 XP+10

Longest Run of Heads

A coin is flipped many times. With a seed, the same flips can be replayed exactly.

Task: write longest_heads_run(seed, flips) that simulates flips coin flips and returns the length of the longest run of heads in a row.

  1. Call random.seed(seed) first.
  2. Make each flip with random.randint(0, 1), one call per flip, in order. 1 is heads and 0 is tails.
  3. Return the longest unbroken run of 1s. With no heads at all (or no flips), return 0.

Examples

seed = 3
flips = 10
returns 2
seed = 1
flips = 0
returns 0

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run