Given a string S, return 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
Inputaabab
Output3
Explanation
A string aabaabaa can be created
Example 2
Inputdog
Output8
Explanation
A string aadaaoaagaa can be created
Example 3
Inputaa
Output0
Explanation
No longer string can be created because it already contains 'aaa'.
Example 4
Inputbaaaa
Output-1
Explanation
Given string contains a substring aaa, hence no additional 'a' can be inserted.