#K81862. First Unique Character in a String
First Unique Character in a String
First Unique Character in a String
Given a string s, determine the index of the first non-repeating character in s. If there is no such character, return -1. This problem tests your ability to work with strings and frequency counting. The input will be provided via standard input and the output should be printed to standard output.
For example:
- Input:
leetcode
→ Output:0
- Input:
loveleetcode
→ Output:2
- Input:
aabb
→ Output:-1
The expected behavior can be concisely represented by the following function signature:
$$\texttt{int first\_uniq\_char(string s)}$$inputFormat
The input consists of a single line containing the string s whose first unique character is to be found. The string may contain any printable characters.
outputFormat
Print a single integer representing the index of the first non-repeating character in s. If no such character exists, print -1.
## sampleleetcode
0