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.
NYJ1qCr, nice! I looked at divmod too but was slower than yours. My is a bit modified for the last part of string but still, I am passing 15 of the 23 cases. Any reason why???
def repeatedString(s, n):
if len(s) == 1:
if s == 'a':
return n
if len(s) < 100 and n <= 10 ** 12:
return ((s * (int(n // len(s)) + 1))[:n]).count('a')
#a, b = divmod(n, len(s))
#return (s * a + s[:b]).count('a')
else:
return 0
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 →
NYJ1qCr, nice! I looked at divmod too but was slower than yours. My is a bit modified for the last part of string but still, I am passing 15 of the 23 cases. Any reason why??? def repeatedString(s, n): if len(s) == 1: if s == 'a': return n if len(s) < 100 and n <= 10 ** 12: return ((s * (int(n // len(s)) + 1))[:n]).count('a') #a, b = divmod(n, len(s))
#return (s * a + s[:b]).count('a') else: return 0