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) {
Character a = new Character('a');
char ch[] = s.toCharArray();
int len = ch.length;
long aInSub=0;
long num = n/len;
long rem = n%len;
long aExtra=0;
for( int i =0; i0){
aExtra++;
}
aInSub++;
}
rem--;
}
return aInSub*num+aExtra;
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 →
You dont need to run two loops.
static long repeatedString(String s, long n) { Character a = new Character('a'); char ch[] = s.toCharArray(); int len = ch.length; long aInSub=0; long num = n/len; long rem = n%len; long aExtra=0; for( int i =0; i0){ aExtra++; } aInSub++; } rem--; }