Hackerrank | Repeated String


Explanation:

  • Count the number of a's in the string.
  • Check the number of times the string is repeated.
  • Check for a's in remaining sub string.

def repeatedString(s, n):
   
    return s.count('a') * (n//len(s)) + s[:n % len(s)].count("a")

Comments

Popular posts from this blog

Hackerrank | Sequence Equation

HackerRank | Organizing Containers of Balls

HackerRank | Minimum Distances