repeated string

\(O(n)\) solution in Python to the repeated string problem from HackerRank:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
def repeatedString(s, n):
    c = 0
    for i in range(len(s)):
        if s[i] == 'a':
            c += 1

    c = c * (n // len(s))
    for i in range(n % len(s)):
        if s[i] == 'a':
            c += 1
    
    return c

if __name__ == "__main__":
    print(repeatedString('abcac', 10))