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 used the same logic but a simpler code. It's the same thing so you can understand.
at first s.count("s") will give the number of a's in one substring.
Multiplying that with (n//len(s)), which is the number of complete substrings present in that repeated string, gives the number of a's till that part.
Now what's left is a smaller (incomplete) part of the substring which is s[0:n%len(s)] ( length of the remaining = the remainder). We just find the number of a's in that part and add it to the previous value of count
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 used the same logic but a simpler code. It's the same thing so you can understand. at first s.count("s") will give the number of a's in one substring. Multiplying that with (n//len(s)), which is the number of complete substrings present in that repeated string, gives the number of a's till that part. Now what's left is a smaller (incomplete) part of the substring which is s[0:n%len(s)] ( length of the remaining = the remainder). We just find the number of a's in that part and add it to the previous value of count