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 have code this in Java 8. Its working very fine.
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.next();
long n = in.nextLong();
int l=s.length();
long count=0,count1=0;
for(int i=0;i<l;i++){
if(s.charAt(i)=='a')
count++;
}
for(int i=0;i<(n%l);i++){
if(s.charAt(i)=='a')
count1++;
}
count = count*(n/l)+ count1;
System.out.println(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 have code this in Java 8. Its working very fine.
import java.util.*;
public class Solution {
}