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
PostgreSQLv16

Qui apparirà il risultato dell'esecuzione del codice

Tests12
Visible tests
Test nascosto 7
Test nascosto 8
Test nascosto 9
Test nascosto 10
Test nascosto 11
Test nascosto 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