Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-148

Runs Test Statistic

Problem

Return the number of runs (maximal blocks of equal values) in a binary sequence. An empty sequence has 0 runs, and each change between adjacent values starts a new run.

Hint

Start counting at 1 for a nonempty sequence, then count value changes.

Test cases

case 1
in: [[1,1,0,0,1]]
expected: 3
case 2
in: [[1,0,1,0,1]]
expected: 5
case 3
in: [[]]
expected: 0
case 4
in: [[0,0,0]]
expected: 1
Starter codePython
def count_runs(sequence):
    # Your code here
    pass

4 test cases · run your code against them in the editor