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.
// Complete the repeatedString function below.
static long repeatedString(String s, long n) {
long len= Long.valueOf(s.length());
int a=0;
for (int i = 0; i < len; i++) {
if (s.charAt(i) == 'a')
++a;
}
long occ = (n/len) * a;
for (int i = 0; i < n%len; i++) {
if (s.charAt(i) == 'a')
++occ;
}
return occ;
}
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 →
This is my solution