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.
I have submitted my code in Python 3. But i am seeing runtime error for few of the testcases. Please suggest what need to change.
!/bin/python3
import math
import os
import random
import re
import sys
def repeatedString(s, n):
# Write your code here
if s == 'a':
return n
elif (1 <= len(s) <= 100) and (1 <= n <=1000000000000):
i = int(n / len(s))
st = s * i
i = int(n % len(s))
st = st + s[0:i]
return (st.count('a'))
else:
return 0
if 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 →
I have submitted my code in Python 3. But i am seeing runtime error for few of the testcases. Please suggest what need to change.
!/bin/python3
import math import os import random import re import sys
def repeatedString(s, n): # Write your code here if s == 'a': return n elif (1 <= len(s) <= 100) and (1 <= n <=1000000000000): i = int(n / len(s)) st = s * i i = int(n % len(s)) st = st + s[0:i] return (st.count('a')) else: return 0 if 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()