Find positions of largest groups of characters in a String with Python
The question
Take a string S
of lowercase letters.
These letters form consecutive groupings of like characters.
Find groups with 3 or more like characters and return a list of lists of starting and ending index for each character group.
Elaboration and examples
If we show an example, we could say S = "abbcccdeffffy"
.
This string has 2 groups, c
and f
who’s consecutive characters are of 3 or more.
You need to return a list of lists with the starting and ending index, for the above example, this would be [[3,5],[8,11]]
Another example would be:
S = "nfjsaaaaaebbfbbbfennjheeeeej"
result = [[4,8],[13,15],[22,26]]
Writing some code
|
|