1436. Destination City => Stepwise Explained 😎| Easy To Understand 🚀
Intuition\nThe code aims to find the destination city given a list of paths. It uses an unordered map to represent the paths between cities and a set to store a
# Intuition\nThe code aims to find the destination city given a list of paths. It uses an unordered map to represent the paths between cities and a set to store all cities. The destination city is the one that does not have an outgoing path.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. **Initialize Data Structures**: Create an unordered map (`m`) to store the paths and a set (`s`) to store all cities.\n2. **Populate Data Structures**: Iterate through the given paths, insert cities into the set, and update the map with the paths.\n3. **Find Destination City**: Iterate through the set to find the city that does not have an outgoing path.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(N + M), where N is the number of paths and M is the number of unique cities.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(M), where M is the number of unique cities\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    string destCity(vector<vector<string>>& paths) {\n        ios_base::sync_with_stdio(false);\n        cin.tie(0);\n        cout.tie(0);\n        \n        // Step 1: Create an unordered map to store the paths, and a set to store all cities\n        unordered_map<string, string> m;\n        unordered_set<string> s;\n        \n        // Step 2: Iterate through the paths to populate the map and set\n        for(auto x : paths)\n        {\n            string s1 = x[0];\n            string s2 = x[1];\n            s.insert(s1);\n            s.insert(s2);\n            m[s1] = s2;\n        }\n        \n        // Step 3: Iterate through the set to find the destination city\n        for(auto x : s)\n        {\n            if(m.find(x) == m.end()) return x;\n        }\n        \n        // Step 4: Return an empty string if no destination city is found (this should not happen)\n        return "";\n}\n\n};\n```
['Hash Table', 'String', 'C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']