Final City
Imagine a chain of trips: you travel from one city to the next, then farther again, until the route ends. Write a function destination_city that receives a list of [from, to] route pairs and finds the city with no outgoing route. Return the name of that final city. It is guaranteed that all routes form one path without loops.
Примеры
Ввод
[["London", "New York"], ["New York", "Lima"], ["Lima", "Sao Paulo"]]Вывод
"Sao Paulo"Ввод
[["B", "C"], ["D", "B"], ["C", "A"]]Вывод
"A"Ввод
[["A", "Z"]]Вывод
"Z"Нужно реализовать
def destination_city(paths: list[list[str]]) -> str:
Теги
stringshashmapset
Logáil isteach chun stair na n-aighneachtaí a fheiceáil
Logáil isteachLogáil isteach chun an Meantóir IS a úsáid
Logáil isteachTests12
Visible tests
Tástáil fholaithe 7
Tástáil fholaithe 8
Tástáil fholaithe 9
Tástáil fholaithe 10
Tástáil fholaithe 11
Tástáil fholaithe 12
They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.
Focus radio
Paused · SomaFM · Fluid