CPP | Faster than 90% | Easy
The solution is based on the fact that the output destination occurs only once.\n\nI have created two arrays , \'start\' and \'end\' which contain start-points.
The solution is based on the fact that the output destination occurs only once.\n\nI have created two arrays , \'start\' and \'end\' which contain start-points. and destination respectively.\n\nIn the second loop, if start == end --> end[i] = "". Removes the element that occurs in the start array.\n\nLast loop finds the only element that is not ""(empty) and returns it.\n\nConsider test-case :-\n\n\t\tpaths = [["London","New York"],["New York","Lima"],["Lima","Sao Paulo"]]\n\t\tstart = ["London","New York","Lima"]\n\t\tend = ["New York","Lima","Sao Paulo"]\n\t\t\n\t\tAfter second loop:\n\t\t\n\t\tstart = ["London","New York","Lima"] // No change\n\t\t\n\t\tend = ["","","Sao Paulo"]\n\t\t\n\t\tThird loop checks for only element in \'end\' and returns it.\n\t\t\n\t\t"Sao Paulo" is returned.\n\t\t\n\t\t\n```\nclass Solution {\npublic:\n    string destCity(vector<vector<string>>& paths) {\n        int len = int(paths.size());\n        string start[len];\n        string end[len];\n        for (int i = 0; i < len; i++) {\n            start[i] = paths[i][0];\n            end[i] = paths[i][1];\n        }\n        for(int i = 0;i < len;i++){\n            for(int j = 0; j < len;j++){\n                if(start[i] == end[j]){\n                    end[j] = "";\n                }\n            }\n        }\n        for(int i = 0;i < len;i++){\n            if(end[i] != ""){\n                return end[i];\n            }\n        }\n        return "";\n    }\n};\n```
['C', 'C++']