Count frequencies, then second pass for first index with count 1.
Input
leetcode
Output
0
loveleetcode
2