You are viewing a single comment's thread. Return to all comments →
static long repeatedString(String s, long n) { int strLength = s.length(); long aOccurrence = 0; long factor = n / strLength; long remainder = n % strLength; for (int i=0; i < strLength; i++) { if (s.charAt(i) == 'a') { aOccurrence += (i < remainder) ? factor + 1 : factor; } } return aOccurrence; }
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 →