Repeated String | HackerRank Solution | Python Programming| Solution

There is a string, , of lowercase English letters that is repeated infinitely many times. Given an integer, , find and print the number of letter a‘s in the first  letters of the infinite string.


The substring we consider is , the first  characters of the infinite string. There are  occurrences of a in the substring.

Function Description

Complete the repeatedString function in the editor below.

repeatedString has the following parameter(s):

  • s: a string to repeat
  • n: the number of characters to consider


  • int: the frequency of a in the substring

Input Format

The first line contains a single string, .
The second line contains an integer, .


  • For  of the test cases, .

Sample Input

Sample Input 0


Sample Output 0


Explanation 0
The first  letters of the infinite string are abaabaabaa. Because there are  a‘s, we return .

Sample Input 1


Sample Output 1


Explanation 1
Because all of the first  letters of the infinite string are a, we return .


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: