Destination City

Easy Topics Company Tags

Each pair in paths describes a directed trip from its first city to its second city. Together, the paths form one continuous route without a cycle, although the pairs can appear in any order. Return the final city on the route: it has no outgoing trip. City names are case-sensitive and may contain spaces.

Example 1:

Input: paths = [["Cedar","Oak"],["Maple","Cedar"]]

Output: "Oak"

Explanation: The route is Maple to Cedar to Oak. Oak has no outgoing trip, so it is the destination.

Example 2:

Input: paths = [["North Bay","South Bay"]]

Output: "South Bay"

Explanation: The only trip ends at South Bay. There are no further trips from that city.

Example 3:

Input: paths = [["a","A"],["A","Z"]]

Output: "Z"

Explanation: City names are case-sensitive: a and A are different cities. Following both trips ends at Z.

Constraints:

  • 1 <= paths.length <= 100
  • Every path contains exactly two different city names.
  • Each city name contains 1 to 10 English letters or spaces.
  • The paths form one continuous directed route without cycles.


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.