Second Minimum Time to Reach Destination | 2 Approaches | FULL DRY RUN | Leetcode 2045

Subscribers:
101,000
Published on ● Video Link: https://www.youtube.com/watch?v=_rnQKrA9xzA



Duration: 1:05:57
7,935 views
416


Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
This is the 54th Video of our Playlist "Graphs : Popular Interview Problems" by codestorywithMIK

Dijkstra's -    • Dijkstra's Algorithm | PART-1 | (Micr...  

In this video we will try to solve a very good Graph Problem : Second Minimum Time to Reach Destination | 2 Approaches | FULL DRY RUN | Leetcode 2045 | codestorywithMIK

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 : Second Minimum Time to Reach Destination | 2 Approaches | FULL DRY RUN | Leetcode 2045 | codestorywithMIK
Company Tags : will update soon
My solutions on Github(C++ & JAVA) - https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/second-...


My DP Concepts Playlist :    • Roadmap for DP | How to Start DP ? | ...  
My Graph Concepts Playlist :    • Graph Concepts & Qns - 1 : Graph will...  
My Recursion Concepts Playlist :    • Introduction | Recursion Concepts And...  
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Intervie...
Instagram :   / codestorywithmik  
Facebook :   / 100090524295846  
Twitter :   / cswithmik  
Subscribe to my channel :    / @codestorywithmik  

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

Summary :
Approach 1: Using Modified Dijkstra's Algorithm

Time Complexity: O(ElogV) - where E is the number of edges and V is the number of vertices.
Space Complexity: O(V+E)
Description:
This approach uses a priority queue (min-heap) to implement a modified version of Dijkstra's algorithm.
Each node keeps track of two distances: the minimum distance (d1) and the second minimum distance (d2).
For each node, if it is reached through a shorter path, update d1; if it is reached through a path that is not the shortest but shorter than the current second shortest, update d2.
The algorithm also accounts for traffic lights, adjusting the travel time if the light is red.
The goal is to find the second minimum time to reach the target node n.
Approach 2: Using Breadth-First Search (BFS)

Time Complexity: O(V+E) - where E is the number of edges and V is the number of vertices.
Space Complexity: O(V+E)
Description:
This approach uses a queue to implement BFS, which processes nodes layer by layer.
Similar to the Dijkstra's approach, it maintains two distances for each node: the minimum distance (d1) and the second minimum distance (d2).
For each node, it processes the current path, updating d1 or d2 as needed.
The algorithm adjusts the travel time based on traffic lights, ensuring that travel only proceeds during green lights.
The goal is to find the second minimum time to reach the target node n.
Key Differences:

Priority Queue vs. Queue:
Approach 1 uses a priority queue to always expand the node with the smallest current distance, ensuring the shortest path is found first.
Approach 2 uses a regular queue, expanding nodes in the order they were discovered, making it simpler but potentially less efficient for weighted graphs.
Efficiency:
Approach 1 is more efficient in terms of finding the shortest paths due to the priority queue but involves higher computational complexity with log V factor.
Approach 2 is straightforward BFS with linear time complexity, but it might not handle weights as optimally as the priority queue method.
Both approaches effectively find the second minimum travel time by leveraging the properties of shortest path algorithms, adjusted for the specific problem constraints such as traffic lights.


✨ Timelines✨
00:00 - Introduction
00:30 - Problem Explanation
08:35 - Thought Process - Dijkstra's
15:26 - How to calculate Green time
25:32 - FULL DRY RUN - Dijkstra's
43:01 - Coding it up - Dijkstra's
48:55 - Thought Process - BFS
52:30 - FULL DRY RUN - BFS
01:01:58 - Coding it up - BFS


#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 #newyear2024




Other Videos By codestorywithMIK


2024-08-08Thank you 60,000 Subscribers ❤️
2024-08-06Spiral Matrix III | Simple Simulation | Made Easy | Leetcode 885 | codestorywithMIK
2024-08-05Integer to English Words | Story To Code | Leetcode 273 | codestorywithMIK
2024-08-03Happy Friendship Day ❤️
2024-08-03Range Sum of Sorted Subarray Sums | Learning Something New | Leetcode 1508 | codestorywithMIK
2024-08-01Make Two Arrays Equal by Reversing Subarrays | Easy | Leetcode 1460 | codestorywithMIK
2024-07-31Minimum Swaps to Group All 1's Together II | 2 Ways | Dry Runs | Leetcode 2134 | codestorywithMIK
2024-07-29Filling Bookcase Shelves | Recursion Memoization | Why not Greedy | Leetcode 1105 | codestorywithMIK
2024-07-28Minimum Deletions to Make String Balanced | Multiple Approaches | Leetcode 1653 | codestorywithMIK
2024-07-27Count Number of Teams | Simple thought process | Intuition | Leetcode 1395
2024-07-26Second Minimum Time to Reach Destination | 2 Approaches | FULL DRY RUN | Leetcode 2045
2024-07-24Find the City With the Smallest Number of Neighbors at a Threshold Distance | 3 Ways | Leetcode 1334
2024-07-22Sort the Jumbled Numbers | 2 Approaches | Leetcode 2191 | codestorywithMIK
2024-07-20Minimum Operations to Make Array Equal to Target | Minimum Number of Increments|Leetcode 3229 & 1526
2024-07-19Build a Matrix With Conditions | BFS | DFS | Detailed Explanation | Leetcode 2392 | codestorywithMIK
2024-07-19Palindrome Partitioning | Using Blue Print | DP On Strings | Leetcode 131 | DP Concepts & Qns-27
2024-07-18Find Valid Matrix Given Row and Column Sums | Simple Approach | Leetcode 1605 | codestorywithMIK
2024-07-18Number of Good Leaf Nodes Pairs | Simple DFS | Dry Run | Leetcode 1530 | codestorywithMIK
2024-07-17Lucky Numbers in a Matrix | 2 Approaches | Dry Run | Leetcode 1380 | codestorywithMIK
2024-07-16Number of Good Leaf Nodes Pairs | Using Graph And BFS | Dry Run | Leetcode 1530 | codestorywithMIK
2024-07-14Step-By-Step Directions From a Binary Tree Node to Another | 2 Approaches | Leetcode 2096