Destination City

EasyArray

Description

Given an array paths where paths[i] = [cityAi, cityBi] means there exists a direct path going from cityAi to cityBi. Return the destination city (the city without any outgoing path).

Examples

Input:paths = [["London","New York"],["New York","Lima"]]
Output:"Lima"
Explanation:

Lima has no outgoing path.

Input:paths = [["Tokyo","Seoul"],["Paris","Tokyo"],["Berlin","Paris"]]
Output:"Seoul"
Explanation:

Following the path chain: Berlin → Paris → Tokyo → Seoul. Seoul is the destination city because it has no outgoing path to any other city.

Input:paths = [["Miami","Orlando"],["Orlando","Chicago"],["Chicago","Denver"]]
Output:"Denver"
Explanation:

Following the path chain Miami → Orlando → Chicago → Denver, Denver is the only city with no outgoing path.

Constraints

  • 1 ≤ paths.length ≤ 100

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.