Условие
Показать переводReturn 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.
Ограничения
0 ≤ length ≤ 100,000
Примеры
Пример 1
Ввод:
text = "swiss"
Ожидаемый вывод:
expected = 1
Ввод:
std::string text = "swiss";
Ожидаемый вывод:
long long expected = 1;
Ввод:
string text = "swiss";
Ожидаемый вывод:
long expected = 1;
Пояснение
s repeats, w appears once at index 1.
Пример 2
Ввод:
text = "aabb"
Ожидаемый вывод:
expected = -1
Ввод:
std::string text = "aabb";
Ожидаемый вывод:
long long expected = -1;
Ввод:
string text = "aabb";
Ожидаемый вывод:
long expected = -1;
Пояснение
Every character repeats: -1.
Ссылки
Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.