Microsoft Online Assessment (OA) - Day of the week that is K days later
Given a string S
, returns the maximum number of letters a
that can be inserted into S
(including at the front and end of S
) so that the resulting string doesn’t contain three consecutive letters a
. If string S
already contains the substring aaa
, then your function should return -1
.
Example 1:
Input: aabab
Output: 3
Explanation:
A string aabaabaa
can be made
Example 2:
Input: dog
Output: 8
Explanation:
A string aadaaoaagaa
can be made
Example 3:
Input: aa
Output: 0
Explanation:
No longer string can be made.
Example 4:
Input: baaaa
Output: -1
Explanation:
There is a substring aaa
Try it yourself
Implementation
1 | 1 |
| |
2 | 2 |
| |
3 | - |
| |
3 | + |
| |
4 | + |
| |
5 | + |
| |
6 | + |
| |
7 | + |
| |
8 | + |
| |
9 | + |
| |
10 | + |
| |
11 | + |
| |
12 | + |
| |
13 | + |
| |
14 | + |
| |
15 | + |
| |
16 | + | ||
4 | 17 |
| |
5 | 18 |
|
Loading full content...