from collections import defaultdict
class Solution:
    def destCity(self, paths: List[List[str]]) -> str:
        deg = defaultdict(int)
        for v, w in paths:
            deg[v] += 1
            deg[w]
        for v in deg:
            if not deg[v]: return v
class Solution {
    public String destCity(List<List<String>> paths) {
        HashSet<String> set1 = new HashSet<>();

        for (int i = 0; i < paths.size(); ++i) {
            set1.add(paths.get(i).get(0));
        }
        for (int i = 0; i < paths.size(); ++i) {
            if (!set1.contains(paths.get(i).get(1))) return paths.get(i).get(1);
        }
        return "placeholder";
    }
}
Destination City
You are given the array paths, where paths[i] = [cityAi, cityBi] means there exists a direct path going from cityAi to cityBi. 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.

&nbsp;
Example 1:

Input: paths = [["London","New York"],["New York","Lima"],["Lima","Sao Paulo"]]
Output: "Sao Paulo" 
Explanation: Starting at "London" city you will reach "Sao Paulo" city which is the destination city. Your trip consist of: "London" -&gt; "New York" -&gt; "Lima" -&gt; "Sao Paulo".


Example 2:

Input: paths = [["B","C"],["D","B"],["C","A"]]
Output: "A"
Explanation: All possible trips are:&nbsp;
"D" -&gt; "B" -&gt; "C" -&gt; "A".&nbsp;
"B" -&gt; "C" -&gt; "A".&nbsp;
"C" -&gt; "A".&nbsp;
"A".&nbsp;
Clearly the destination city is "A".


Example 3:

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


&nbsp;
Constraints:


	1 &lt;= paths.length &lt;= 100
	paths[i].length == 2
	1 &lt;= cityAi.length, cityBi.length &lt;= 10
	cityAi != cityBi
	All strings consist of lowercase and uppercase English letters and the space character.


 * @param {string[][]} paths
 * @return {string}
 */
var destCity = function(paths) {
    
    
    let map={}
    
    for(let city of paths){
        map[city[0]]=map[city[0]]?map[city[0]]+1:1
    }
    for(let city of paths){
        if(!map[city[1]]) return city[1]
    }
};```
class Solution {
public:
    string destCity(vector<vector<string>>& paths) {
        string ans;
        unordered_map<string, int> m;
        for(int i=0; i<paths.size(); i++){
            m[paths[i][0]]++;
            m[paths[i][1]]--;
        }
        for(auto city : m){
            if(city.second == -1) ans = city.first;
        }

        return ans;
    }
};