Implement the firstUniqueCharacterIndex method that returns the index of the first character that appears only once.

The input contains a string text. Your task is to return the index of the first character that appears exactly once in the string.

If every character appears more than once, return -1. Indexing starts from 0, so in leetcode, the character l is unique and appears at index 0.

Example 1
Input:
text (string) = leetcode
Return:
(int) 0
Example 2
Input:
text (string) = loveleetcode
Return:
(int) 2
Example 3
Input:
text (string) = aabb
Return:
(int) -1

Count how many times each character appears in the string.

After building the frequency map, scan the string again from left to right. The first position whose character has frequency 1 is the required answer.

If the second scan finishes without finding such a character, no unique character exists.

Pseudocode:

function firstUniqueCharacterIndex(text):
    frequency = empty map
    for each character ch in text:
        frequency[ch]++
    for i from 0 to length(text) - 1:
        if frequency[text[i]] == 1:
            return i
    return -1
Run your code to see the result.