• + 2 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;
    }