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.
static long repeatedString(String s, long n) {
char[] chrIn = s.toCharArray();
int i = 0;
long max = 0;
long quo = n / chrIn.length;
long rem = n % chrIn.length;
while (i < chrIn.length) {
if (chrIn[i] == 'a') {
max++;
}
i++;
}
i = 0;
max = max * quo;
while (i < rem) {
if (chrIn[i] == 'a') {
max++;
}
i++;
}
return max;
}
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 →
try this
static long repeatedString(String s, long n) { char[] chrIn = s.toCharArray(); int i = 0; long max = 0; long quo = n / chrIn.length; long rem = n % chrIn.length; while (i < chrIn.length) { if (chrIn[i] == 'a') { max++; } i++; } i = 0; max = max * quo; while (i < rem) { if (chrIn[i] == 'a') { max++; } i++;