Skip to content

Commit 3eff11a

Browse files
committed
Solve : Repeated String
1 parent 69f7d84 commit 3eff11a

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

Easy/RepeatedString.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Solution 1
2+
function repeatedString(s, n) {
3+
const repeatCount = Math.floor(n / s.length);
4+
const remainder = n % s.length;
5+
let maxCount = 0;
6+
7+
for (let i = 0; i < s.length; i++) {
8+
if (s.charAt(i) === 'a') {
9+
maxCount += repeatCount;
10+
11+
if (i < remainder) {
12+
maxCount++;
13+
}
14+
}
15+
}
16+
17+
return maxCount;
18+
}

0 commit comments

Comments
 (0)