• + 0 comments

    python solution:

    def repeatedString(s, n):
        # Count 'a's in one full instance of string 's'
        countInOneInstance = s.count('a')
    
        # Calculate how many full instances of 's' can fit in 'n'
        countInFullInstance = countInOneInstance * (n // len(s))
    
        # Count 'a's in the remaining part of the string (if any)
        countInPartInstance = 0
        numFirstCharsToCount = n % len(s)
    
        for i in range(numFirstCharsToCount):
            if s[i] == 'a':
                countInPartInstance += 1
    
        return countInFullInstance + countInPartInstance