Microsoft Online Assessment (OA) - Longest Substring Without Two Contiguous Occurrences of Letter
Given a string str
containing only a
and b
, find the longest substring of str
such that str
does not contain more than two contiguous occurrences of a
and b
.
Example 1:
Input: aabbaaaaabb
Output: aabbaa
Example 2:
Input: aabbaabbaabbaaa
Output: aabbaabbaabbaa
Try it yourself
Implementation
1 | + |
| |
1 | 2 |
| |
2 | - |
| |
3 | + |
| |
4 | + |
| |
5 | + |
| |
6 | + |
| |
7 | + |
| |
8 | + |
| |
9 | + |
| |
10 | + |
| |
11 | + |
| |
3 | 12 |
| |
4 | 13 |
|
Loading full content...