#K6536. First Unique Character Index

    ID: 32180 Type: Default 1000ms 256MiB

First Unique Character Index

First Unique Character Index

Given a string \( s \), your task is to find the index of the first unique character in \( s \). A character is considered unique if it appears exactly once in the string. The search is case-sensitive, meaning that uppercase and lowercase characters are treated as distinct.

If no unique character exists in the string, output \( -1 \). In formal terms, you are to compute

\( \displaystyle \text{result} = \min\{ i \mid 0 \le i < n \wedge \text{freq}(s[i]) = 1 \} \)

with the convention that if no such \( i \) exists, then \( \text{result} = -1 \).

inputFormat

The input consists of a single line containing a non-empty string \( s \). The string has at most 105 characters.

outputFormat

Output a single integer which is the index of the first unique character in \( s \). If no unique character exists, output -1.

## sample
leetcode
0