Problema
Ver traducciónReturn 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.
Restricciones
0 ≤ length ≤ 100,000
Ejemplos
Ejemplo 1
Entrada:
text = "swiss"
Salida esperada:
expected = 1
Entrada:
std::string text = "swiss";
Salida esperada:
long long expected = 1;
Entrada:
string text = "swiss";
Salida esperada:
long expected = 1;
Explicación
s repeats, w appears once at index 1.
Ejemplo 2
Entrada:
text = "aabb"
Salida esperada:
expected = -1
Entrada:
std::string text = "aabb";
Salida esperada:
long long expected = -1;
Entrada:
string text = "aabb";
Salida esperada:
long expected = -1;
Explicación
Every character repeats: -1.
Referencias
Este reto está adaptado para CodeUtility. Sigue el enunciado y las restricciones indicadas arriba.