Unique String in Order

In lists, you often need to find items that appear only once, such as unique names or rare commands. Write a function kth_distinct that finds the k-th string that appears exactly once in arr. Keep the original order of appearance when counting distinct strings. If there are fewer than k distinct strings, return an empty string.

Примеры

Ввод
["d", "b", "c", "b", "c", "a"], 2
Вывод
"a"
Ввод
["aaa", "aa", "a"], 1
Вывод
"aaa"
Ввод
["a", "b", "a"], 3
Вывод
""

Нужно реализовать

def kth_distinct(arr: list[str], k: int) -> str:

Теги

stringshashmapdict
PostgreSQLv16

Tu sa zobrazí výsledok spustenia kódu

Visible tests
1
Input
["d","b","c","b","c","a"], 2
Expected"a"
2
Input
["aaa","aa","a"], 1
Expected"aaa"
3
Input
["a","b","a"], 3
Expected""
4
Input
["x","y","z"], 2
Expected"y"
5
Input
["a","a","b"], 1
Expected"b"
6
Input
["one","two","two","one","three"], 1
Expected"three"
Focus radio
Paused · SomaFM · Fluid