Recurring Character
Given a lowercase alphabet string s, return the index of the first recurring character in it. If there are no recurring characters, return -1.
Constraints
n ≤ 100,000wherenis the length ofs
https://binarysearch.com/problems/Recurring-Character
Examples
Example 1
Input
- s =
abcde
Output
- answer =
-1
Explanation
No recurring characters in this string.
Example 2
Input
- s =
aaaaa
Output
- answer =
1
Explanation
We want the first recurring character.
Example 3
Input
- s =
abcda
Output
- answer =
4
Explanation
The a at index 4 is the first recurring character.
Leave a comment