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
Entre para ver seu histórico de envios
EntrarEntre para usar o AI Mentor
EntrarVisible tests
1
Input
[["London","New York"],["New York","Lima"],["Lima","Sao Paulo"]]Expected
"Sao Paulo"2
Input
[["B","C"],["D","B"],["C","A"]]Expected
"A"3
Input
[["A","Z"]]Expected
"Z"4
Input
[["x","y"],["y","z"]]Expected
"z"5
Input
[["start","end"]]Expected
"end"6
Input
[["jfk","sfo"],["sfo","lax"]]Expected
"lax"Focus radio
Paused · SomaFM · Fluid