INSTDUM - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Authors: d_k_7386, preet_25
Tester: tabr
Editorialist: iceknight1093

DIFFICULTY:

895

PREREQUISITES:

None

PROBLEM:

Given the runs scored in each of N balls, find the number of times when the strike rate was exactly 100.

EXPLANATION:

Recall that the strike rate is defined as

\frac{ \text{total runs scored} } { \text{balls faced} } \cdot 100

This equals 100 if and only if the number of runs scored equals the number of balls faced.

After i balls, the number of runs scored is exactly A_1 + A_2 + \ldots + A_i.
So, the answer is simply the number of i such that A_1 + A_2 + \ldots + A_i = i.

This can be easily computed in \mathcal{O}(N) with a simple loop.

TIME COMPLEXITY

\mathcal{O}(N) per test case.

CODE:

Editorialist's code (Python)
for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    runs, ans = 0, 0
    for i in range(n):
        runs += a[i]
        if runs == i+1: ans += 1
    print(ans)