Index of the First Non-Repeating Character
Problem statement
Given a non-empty string s, return the zero-based index of the first character whose total frequency in the string is exactly one.
If no such character exists, return -1. Character comparisons are case-sensitive.
Function
firstNonRepeatingIndex(s: String) → intExamples
Example 1
s = "swiss"return = 1The character s repeats, while w occurs once at index 1.
Example 2
s = "aabbc"return = 4Only c has frequency one, and its index is 4.
Example 3
s = "aabb"return = -1Every character repeats, so there is no qualifying index.
Constraints
1 ≤ s.length ≤ 100000.scontains printable ASCII characters.