#K79762. First Non-Repeating Character Index
First Non-Repeating Character Index
First Non-Repeating Character Index
Given an integer \(T\) and \(T\) strings, for each string determine the index of the first character that does not repeat within that string. If every character in a string repeats, output \(-1\) for that case.
For instance, if the input string is "leetcode", the first non-repeating character is 'l' at index 0. If the string is "loveleetcode", the first unique character is 'v' at index 2. In a string such as "aabbccddeeff", all characters appear more than once, so the answer is \(-1\).
This problem requires processing each test case individually. The overall time complexity per test case is \(O(n)\), where \(n\) is the length of the string, since we must check each character.
inputFormat
The input is read from the standard input (stdin) and is structured as follows:
- The first line contains an integer \(T\), representing the number of test cases.
- The following \(T\) lines each contain a single string.
Each string consists of only lowercase or uppercase alphabetic characters without spaces.
outputFormat
For each test case, output the index of the first non-repeating character on a new line. If no such character exists, output \(-1\) for that test case.
## sample1
leetcode
0
</p>