We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#!/bin/python3importmathimportosimportrandomimportreimportsys## Complete the 'repeatedString' function below.## The function is expected to return a LONG_INTEGER.# The function accepts following parameters:# 1. STRING s# 2. LONG_INTEGER n#defrepeatedString(s,n):# Write your code herecount_a_in_s=s.count('a')full_repeats=n// len(s)total_a_in_full_repeats=full_repeats*count_a_in_sremainder=n%len(s)total_a_in_remainder=0foriinrange(remainder):ifs[i]=='a':total_a_in_remainder+=1total_a=total_a_in_full_repeats+total_a_in_remainderreturntotal_aif__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')s=input()n=int(input().strip())result=repeatedString(s,n)fptr.write(str(result)+'\n')fptr.close()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Repeated String
You are viewing a single comment's thread. Return to all comments →
My solution using Python.