See the original problem on HackerRank.
l the length of the string. Thus, we have
copies = n / l copies of the string.
occ the number of occurrences of
a in the string. Thus, we have at least
occ * l occurrences of
The extra number of
a is calculated from the possible remainder of the first
n / l characters in the string. So we calculate the number of
a in the first
Here is a C++ solution:
An alternative solution in Python:
- don’t use the module operator