Destination City

EasyArrays & Hashinghashing

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You are given a list of one-way flights paths, where paths[i] = [from, to] means there is a direct route from city from to city to. Taken together, the routes form a single chain with no loops, so exactly one city has no outgoing route. Return the name of that final city (the one that never appears as a departure).

Examples

Input: paths = [["Boston","Denver"],["Denver","Austin"],["Austin","Miami"]]
Output: "Miami"
The trip goes Boston -> Denver -> Austin -> Miami, and Miami has no outgoing route.
Input: paths = [["X","Y"]]
Output: "Y"
The only route ends at Y.

Constraints

  • 1 <= paths.length <= 100
  • paths[i].length == 2
  • 1 <= length of each city name <= 10
  • from != to for every route
  • The routes form one simple chain, so the answer is unique

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More hashing problems