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

Her vises resultatet af din kode

Tests12
Visible tests
Skjult test 7
Skjult test 8
Skjult test 9
Skjult test 10
Skjult test 11
Skjult test 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