repeatedString HackerRank Solution: Looking for repeatedString solution for Hackerrank problem? Get solution with source code and detailed explainer video
There is a string,s, of lowercase English letters that is repeated infinitely many times. Given an integer,n, find and print the number of letter a’s in the first n letters of the infinite string.
Example :
s=’abcac’
n=10
Go to problem statement
Explanation Video:
Youtube Channel partner: CodingCart
Mentor: Satyendra Jaiswal
Langauge: Python
Source Code: for repeatedString
function
# Complete the repeatedString function below.
def repeatedString(s, n):
n1=(n//len(s))
x=s.count('a')
x1=n1*x
x2=s[:n%(len(s))].count('a')
return x1+x2
coming soon…
coming soon…
Full Source Code:
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the repeatedString function below.
def repeatedString(s, n):
n1=(n//len(s))
x=s.count('a')
x1=n1*x
x2=s[:n%(len(s))].count('a')
return x1+x2
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
s = input()
n = int(input())
result = repeatedString(s, n)
fptr.write(str(result) + '\n')
fptr.close()
coming soon…
coming soon…
Like this article? Follow us on Facebook and LinkedIn. You can also subscribe to our Youtube Channel.
This post is in partner with CodingCart.