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
Влез, за да видиш историята на решенията
ВходВлез, за да използваш ИИ ментора
ВходTests12
Visible tests
Скрит тест 7
Скрит тест 8
Скрит тест 9
Скрит тест 10
Скрит тест 11
Скрит тест 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