Shortest Path Visiting All Nodes | Leetcode 847 | Live coding session 🔥🔥 | BFS + Bit Manipulation
Vložit
- čas přidán 24. 02. 2022
- Here is the solution to "Shortest Path Visiting All Nodes" leetcode question. Hope you have a great time going through it.
🔴 Question:leetcode.com/problems/shortes...
🔥Don't click: bit.ly/32XIXbU
🔥Linkedin: bit.ly/3n65udU
🔥Insta: bit.ly/31TV5ur
👉 Solutions
Java github.com/Sunchit/Coding-Dec...
C++
github.com/Sunchit/Coding-Dec...
🔥🔥🔥🔥👇👇👇 For discussion/feedback/humour/doubts/new openings
Feel free to join discord / discord
🔴 Checkout the series: 🔥🔥🔥
👉 Leetcode Interview experiences and tips : • Playlist
👉 Leetcode contests: www.youtube.com?list=PLEI-q7w3s9gRwAEYzYkvVTsYHDi2-ffdL
👉 Leetcode System Design: • System Design
👉 Leetcode LinkedList: • Coding Decoded LinkedL...
👉 Leetcode Stack: • Coding Decoded Stack S...
👉 Leetcode Binary Search: • Coding Decoded BinaryS...
👉 Leetcode Tree: • Coding Decoded Tree Se...
👉 Leetcode Dyanmic Programming: • Coding Decoded Dynamic...
👉 Leetcode Hard: • LeetCode Hard Problems
👉 Leetcode Heap: • Coding Decoded Heap Se...
👉 Building Coding Aptitude: • Building Coding Aptitude
👉 Leetcode Map: • Coding Decoded Map Ser...
👉 Leetcode Two Pointer: • Coding Decoded Two Poi...
👉 Leetcode Backtracking: • Leetcode Backtracking ...
👉 Leetcode Graph Traversal: • Coding Decoded Graph T...
👉 Leetcode Trie: • Coding Decoded Trie Se...
👉 Leetcode Union Find: • Coding Decoded Union F...
👉 Leetcode BFS Graph Problems: • Coding Decoded BFS Ser...
👉 Leetcode Matrix Problems: • Coding Decoded Matrix ...
👉 Leetcode Easy: • Leetcode Easy Problems
👉 Leetcode Bit Manipulation: • Coding Decoded Bit Man...
🔥🔥🔥 Leetcode Monthly Contest Playlist
👉 Leetcode December 2021: www.youtube.com?list=PLEI-q7w3s9gRN3LsF0zArurVSz3HQyKZP
👉 Leetcode November 2021: www.youtube.com?list=PLEI-q7w3s9gT2IeinxSocuxyOKMB4H2zF
👉 Leetcode October 2021: www.youtube.com?list=PLEI-q7w3s9gTNU412xW8kV1xQ8upnrN0a
👉 Leetcode September 2021: www.youtube.com?list=PLEI-q7w3s9gTNU412xW8kV1xQ8upnrN0a
👉 Leetcode August2021: www.youtube.com?list=PLEI-q7w3s9gTEQxR2uR-g8DVhSTb2ZAx1
👉 Leetcode July 2021: www.youtube.com?list=PLEI-q7w3s9gRV3Bn3VO1rtgkA0wNkIm-y
👉 Leetcode June 2021: www.youtube.com?list=PLEI-q7w3s9gRGYr0jtVjqir5_8SpnQ6Og
👉 Leetcode May 2021: www.youtube.com?list=PLEI-q7w3s9gS8UNo22UA4O3_YjnQczyNp
👉 Leetcode April 2021: www.youtube.com?list=PLEI-q7w3s9gStjIegCW3i84AI9L2KjGhJ
👉 Leetcode March 2021: www.youtube.com?list=PLEI-q7w3s9gTbYRnbU7Np0_-v_GwxYGOb
👉 Leetcode Feb 2021: www.youtube.com?list=PLEI-q7w3s9gRNUjYwtb53A7SXSCQaJguT
👉 Leetcode Jan 2021: www.youtube.com?list=PLEI-q7w3s9gR8EhTsObcgM74NnIiAcRWm
👉 Leetcode December 2020: www.youtube.com?list=PLEI-q7w3s9gQIB_urBmMV04f_NBelXJEP
PS : Please increase the speed to 1.25X
Nice explanation !!
Bro, very nice explanation. Keep up this discipline and consistency
Nicely Explained
Thanks for such simple explanation. Keep up the good work:)
Idk why people teaching in other videos feel the need to teach bit manipulation from scratch on every step and waste the time. If someone is doing this problem he should already be assumed to be knowing bit manipulation.
Finally this video gives the good talk. Thanks.
Felt easy problem initially till realized about usual visited can’t be used. Thanks for great explanation.
Thanks for the solution!
Great Explanation!
Very good explanation brother. Thanks for this
love you!
with your video, i understand the answer in just 10 minutes. It is like a magic!
Wonderful!
Thank you so much , was struggling with this question since morning !!
Happy to help, do watch out the graph series if u are interested in more such questions
very nice explnation
Finallyyyy Understood!!!
Great
Crystal clear explaination : )
best explanation availabel on internet for this problem.
Nice explanation
Epic Explanation
Another outstanding explanation. Thanks a lot :).
Bimurta my frds used to call me sanchi in college .... Haha
Good to hear 🙂
Thanks..🙌
thanks a lot
Awesome Bhai. I Appreciate.
Great Explanation
Crisp short to the point solution.Just Loved it!
Best explanation ⚡
just wow.
im in love with bitmasks now....
great explaination.......tooo....
Thanks 👍
Thanks!
Thanks Gaurav
Well Explained bro, need to dry run the solution to understand it fully
When I feel sleeplessness, I watch his videos :) Thanks man for that
can you explain how this solves the problem of choosing the shortest path?,, like how does adding ebverything to the queue initiallly and doing for loop till size of queue enssure we get the shortest path among all the paths
thanks
bfs does the magic here.first we move at distance 1 from each starting node ,then we move at distance 2 from each starting node,in this way the first time we have covered all nodes from a starting node it will be the shortest distance.
Great explanation!
Glad it was helpful!
Could you please explain why you have used loop inside while loop ,?
Time complexity of this approach?
Thanks bro
Welcome
Suppose we would have had 3 also attached to 0. Then we would go to 2 and come back to 0, and there then we would again go back to 1 as, that state would not have visited before?
You are simply amazing 😁
you too bro
You are amazing!
You too!!
ver nice explanation
Thanks for liking
Most youtuber explained this question like "Ratta". Thanks for this amazing video and explained very well.
Thanks to your videos, I managed to get a position at Pinterest! Bro you are the fking best
Heartiest congratulations @Y C, let us connect on linkedin www.linkedin.com/in/coding-decoded-6809a3215/
Well explained man!
Thanks Umesh, watch out the entire series you will simply love it
@@CodeWithSunchitDudeja Ik bro, have been seeing your videos from quite a long time. Always understood the solution :) One feedback though, try adding your own face in the video to feel more like as if some human is teaching us! Something like pep coding.
@@umeshhbhat thanks for the tip man.. will come over video
very soon
SOlid explanatory video
You said we need to apply this starting from every node right? but we are applying it for only one node to start with. Didn't get it
Nice one to know 👌👏 is it travelling salesman problem with unweighted edges? Also how can we calculate time complexity?
Yes it is similar to that
Yea it's a variation of travelling salesman.
isnt just knowing about the parent node enough to avoid indefinite loops
The BFS Solution is a lot more straightforward than the DFS one.
Sorry if I missed something in the video.. if we have to do independent BFS from each node, why isn't shortest path variable reset to zero? I see you added all vertices to queue in the beginning only.. Why does it not cause any problem?
My bad, understood the concept now. Thanks for the video.
how can we know where to use bit manipulation . i mean intuition to use bit??
Bit Vector can be generally used in place of arrays when the problem needs the state which can vary from 0 to 2^n-1, n being the length of the array which is nodes in this case. Helps with saving space, CPU operations are also faster on bits.
Hey is Leetcode hard necessary for interviews and online coding round?
For FAANG/MAANG yes
is this question might come in interview as the level is question is little bit high?
As an interviewer, who have interviewed more than 100 candidates I will never ask this question. In case it comes ask the interviewer can you solve it haha :)...PS : Google is an exception to this list
prettiest 😢
a suggestion : u can use wacom tablet with pen to write instead of mouse. That will improve your efficiency. you can check mine videos.
Thanks thinkcode for the advice
C++ code, if anyone needs it
class Solution {
public:
/* a type of multisource bfs with each node as source
->BFS traversal from all nodes
->Basic BFS while maintaining visited arr will not work because we will be revisiting a node if necessary
->we need to avoid infinite loop, for this we will maintain the visited state of nodes(in bitmask) with current visiting node in a queue.
In example 1, final bitmask will look like 1111
*/
int shortestPathLength(vector& graph) {
int n = graph.size();
if(n==1) return 0;
int final_bitState = (1
thank you
useful
arre bhai jisne yeh ques pehle nahi dekha woh kaise solve karega interview main. total chutiyapa chal raha hain