Problema
Ver traduçãoReturn the index of the first character in text that appears exactly once. Case matters.
Implement first_unique_index(text).
Input
text: The text to inspect.
Output
Return the index, or -1 if every character repeats.
Restrições
0 ≤ length ≤ 100,000
Exemplos
Exemplo 1
Entrada:
text = "swiss"
Saída esperada:
expected = 1
Entrada:
std::string text = "swiss";
Saída esperada:
long long expected = 1;
Entrada:
string text = "swiss";
Saída esperada:
long expected = 1;
Explicação
s repeats, w appears once at index 1.
Exemplo 2
Entrada:
text = "aabb"
Saída esperada:
expected = -1
Entrada:
std::string text = "aabb";
Saída esperada:
long long expected = -1;
Entrada:
string text = "aabb";
Saída esperada:
long expected = -1;
Explicação
Every character repeats: -1.
Referências
Este desafio foi adaptado para o CodeUtility. Siga o enunciado e as restrições acima.