#C10707. First Non-Repeating Character
First Non-Repeating Character
First Non-Repeating Character
Given a string \(S\) consisting of lowercase English letters, find the index of the first non-repeating character in \(S\). If no such character exists, output \(-1\).
Example:
- For \(S = "geeksforgeeks"\), the answer is \(5\) because the first non-repeating character is 'f' at index 5.
- For \(S = "abcabc"\), the answer is \(-1\) because every character repeats.
Your program should read the input from stdin
and output the result to stdout
.
inputFormat
The input consists of a single line containing the string \(S\) where \(1 \leq |S| \leq 10^5\). The string consists only of lowercase English letters.
outputFormat
Output a single integer which is the index (0-indexed) of the first non-repeating character in \(S\). If there is no such character, output \(-1\).
## samplegeeksforgeeks
5