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
Logga in för att se historik över inskick
Logga inLogga in för att använda AI-mentorn
Logga inVisible tests
1
Input
["d","b","c","b","c","a"], 2Expected
"a"2
Input
["aaa","aa","a"], 1Expected
"aaa"3
Input
["a","b","a"], 3Expected
""4
Input
["x","y","z"], 2Expected
"y"5
Input
["a","a","b"], 1Expected
"b"6
Input
["one","two","two","one","three"], 1Expected
"three"Focus radio
Paused · SomaFM · Fluid