Destination City | 2 Approaches | Leetcode-1436
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 9th Video of our Playlist "Leetcode Easy".
In this video we will try to solve an easy but good practice problem - Destination City (Leetcode - 1436).
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.
Problem Name : Destination City
Company Tags : Will soon update
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/HashMap/Destination%20City.cpp (Using HashMap)
https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/HashSet/Destination%20City.cpp (Using HashSet)
Leetcode Link : https://leetcode.com/problems/destination-city/
My DP Concepts Playlist : https://youtu.be/7eLMOE1jnls
My Graph Concepts Playlist : https://youtu.be/5JGiZnr6B5w
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Subscribe to my channel : https://www.youtube.com/@codestorywithMIK
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Approach Summary - HashMap :
The code uses an unordered map (unordered_map string, int mp) to keep track of the outdegree of each city. It first iterates through the paths to count the outdegree of each source city and stores the count in the map. Then, it iterates through the paths again, checking the outdegree of the destination city. If the outdegree is zero, meaning the city is not a source city in any path, it returns that city as the destination. If no such city is found, an empty string is returned. The approach efficiently determines the destination city by analyzing the outdegree of each city in the given paths.
Approach Summary - HashSet :
The code uses an unordered set (unordered_set string st) to store the source cities. In the first loop, it iterates through the paths, inserting each source city into the set. Then, in the second loop, it iterates through the paths again, checking if the destination city is not present in the set of source cities. If a city with no corresponding source is found, it returns that city as the destination. If no such city is found, an empty string is returned. The approach effectively identifies the destination city by checking for the absence of the city in the set of source cities.
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
✨ Timelines✨
00:00 - Introduction
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa