An airport's runway edge-lighting system reports its status once per second as a string of lowercase letters, where each character encodes the color code currently displayed by the beacon at that position along the runway (position 0 is nearest the threshold). Beacons of the same color sitting next to one another form a continuous streak. Maintenance flags any streak of three or more beacons as a fault zone that needs inspection, since an unbroken streak that long usually means the color-cycling relay is stuck. Given the beacon status string, report every fault zone, in the order the streaks occur along the runway, as its start and end position.
A single line containing a string s (1 <= |s| <= 10^5) of lowercase English letters, giving the beacon color code at each position along the runway, from position 0 to position |s| - 1.
Print the fault zones in increasing order of start position, one per line, each as two space-separated integers start end (0-indexed, inclusive) giving the bounds of that streak. If there are no fault zones, print nothing.
s consists only of lowercase English letters ('a'-'z').Example 1
Input
aaabbbbcc
Expected
0 2 3 6
Explanation
The string breaks into runs 'aaa' (positions 0-2, length 3), 'bbbb' (positions 3-6, length 4), and 'cc' (positions 7-8, length 2). The first two runs reach the length-3 threshold and are reported in order, giving '0 2' then '3 6'; the last run has length 2 and is skipped.
Example 2
Input
abcd
Expected
(empty)Explanation
Every character differs from its neighbors, so each one forms its own run of length 1. No run reaches the length-3 threshold, so the program prints nothing.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →