Given a string s consisting of lowercase letters, your task is to determine if there exists a contiguous substring of s that is unbalanced. A string is defined as unbalanced if the following conditions are met:
The length of the string is at least 2.
More than half of the letters in the string are the same.
Examples of Unbalanced Strings:
voodoo (more than half are 'o')
melee (more than half are 'e')
Examples of Non-Unbalanced Strings:
noon (no letter occurs more than half)
a (not long enough)
Input Format
A single string s of length n (where n ≥ 1) containing only lowercase letters.
Output Format
If an unbalanced substring exists, print the starting index (0-based) of the substring.
If no unbalanced substring exists, print -1.
Example Scenarios
Input 1:
text
s = "voodoos"
Output 1:
text
0
Input 2:
text
s = "noon"
Output 2:
text
-1
Constraints
The length of the string s will be at least 1 and will not exceed 100.
Place your solution in:
/app/
Notes
Make sure to handle various lengths of strings and potential edge cases.