You are viewing a single comment's thread. Return to all comments →
Here's a solution in Python that does not need any for loops and can handle even high numbers for n
n
def repeatedString(s: str, n: int) -> int: s_len = len(s) repetitions_needed = n // s_len remaining_chars = n % s_len occurrences_of_a = s.count('a') * repetitions_needed if remaining_chars: occurrences_of_a += s[:remaining_chars].count('a') return occurrences_of_a
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 →
Here's a solution in Python that does not need any for loops and can handle even high numbers for
n