• + 0 comments

    Java 15

    class Result {
    
        private static final IntPredicate isA = c -> c == 'a';
    
        public static long repeatedString(String s, long n) {
          long times = n / s.length();
          long remainingChars = n % s.length();
          long count = s.chars().filter(isA).count();
          count*=times;  
          count += s.substring(0, (int) remainingChars).chars().filter(isA).count();  
          return count;
        }
    
    }