Destination City Problem
Destination City Problem — ExecCode Easy DSA Practice
Solve the Destination City problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given the array paths, where paths[i] = [cityAi, cityBi] means there exists a direct path going from cityAi to cityBi. Your task is to compute the required answer and return the destination city, that is, the city without any path outgoing to another city. It is guaranteed that the graph of paths forms a line without any loop, therefore, there will be exactly one destination city.
Examples
Input {"paths": [["London", "New York"], ["New York", "Lima"], ["Lima", "Sao Paulo"]]}; Output Sao Paulo. Input {"paths": [["B", "C"], ["D", "B"], ["C", "A"]]}; Output A
Constraints
1 <= paths.length <= 100 paths[i].length == 2 1 <= cityAi.length, cityBi.length <= 10 cityAi != cityBi All strings consist of lowercase and uppercase English letters and the space character.
Practice Destination City free on ExecCode. Browse DSA problems, topic map, and placement guides.