Shortest Path Visiting All Nodes | Leetcode 847 | Live coding session 🔥🔥 | BFS + Bit Manipulation

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

Пікірлер: 78

  • @theghostwhowalk
    @theghostwhowalk2 жыл бұрын

    Felt easy problem initially till realized about usual visited can’t be used. Thanks for great explanation.

  • @sidhantsharma5984
    @sidhantsharma59842 жыл бұрын

    Bro, very nice explanation. Keep up this discipline and consistency

  • @rishabhrawat7943
    @rishabhrawat79432 жыл бұрын

    Thanks for such simple explanation. Keep up the good work:)

  • @hoyinli7462
    @hoyinli74622 жыл бұрын

    love you! with your video, i understand the answer in just 10 minutes. It is like a magic!

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    2 жыл бұрын

    Wonderful!

  • @sayanchandra9479
    @sayanchandra94792 жыл бұрын

    Thank you so much , was struggling with this question since morning !!

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    2 жыл бұрын

    Happy to help, do watch out the graph series if u are interested in more such questions

  • @divanshuagarwal8236
    @divanshuagarwal82362 жыл бұрын

    Thanks for the solution!

  • @aaravarya4406
    @aaravarya4406 Жыл бұрын

    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.

  • @CUTIE-PIE-KRISHIKA
    @CUTIE-PIE-KRISHIKA2 жыл бұрын

    best explanation availabel on internet for this problem.

  • @Ganeshkanagavel
    @Ganeshkanagavel5 күн бұрын

    Nicely Explained

  • @noobbot7392
    @noobbot73922 жыл бұрын

    Very good explanation brother. Thanks for this

  • @Sujith0369
    @Sujith036910 ай бұрын

    Crisp short to the point solution.Just Loved it!

  • @varunsaraf8018
    @varunsaraf80182 жыл бұрын

    Great Explanation!

  • @anuragchakraborty7607
    @anuragchakraborty76072 жыл бұрын

    very nice explnation

  • @mainakmondal5228
    @mainakmondal52285 ай бұрын

    Nice explanation

  • @harshthakkar7503
    @harshthakkar7503 Жыл бұрын

    Crystal clear explaination : )

  • @bimurtabismoysanchi4029
    @bimurtabismoysanchi40292 жыл бұрын

    Another outstanding explanation. Thanks a lot :).

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    2 жыл бұрын

    Bimurta my frds used to call me sanchi in college .... Haha

  • @bimurtabismoysanchi4029

    @bimurtabismoysanchi4029

    2 жыл бұрын

    Good to hear 🙂

  • @shyamsundar214
    @shyamsundar2142 жыл бұрын

    Epic Explanation

  • @manojjain3501
    @manojjain35012 жыл бұрын

    Awesome Bhai. I Appreciate.

  • @MrVrtex
    @MrVrtex10 ай бұрын

    When I feel sleeplessness, I watch his videos :) Thanks man for that

  • @abhishek__anand__
    @abhishek__anand__10 ай бұрын

    Great Explanation

  • @trevorPhillips284
    @trevorPhillips2842 жыл бұрын

    Well Explained bro, need to dry run the solution to understand it fully

  • @utsavgupta746
    @utsavgupta7462 жыл бұрын

    Thanks..🙌

  • @commentator2407
    @commentator24072 жыл бұрын

    just wow. im in love with bitmasks now.... great explaination.......tooo....

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    2 жыл бұрын

    Thanks 👍

  • @Ryan-mr9pn
    @Ryan-mr9pn2 жыл бұрын

    Best explanation ⚡

  • @prakhyat2001
    @prakhyat200110 ай бұрын

    thanks a lot

  • @shivam7271
    @shivam72712 жыл бұрын

    Finallyyyy Understood!!!

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    2 жыл бұрын

    Great

  • @MrACrazyHobo
    @MrACrazyHobo2 жыл бұрын

    Thanks to your videos, I managed to get a position at Pinterest! Bro you are the fking best

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    2 жыл бұрын

    Heartiest congratulations @Y C, let us connect on linkedin www.linkedin.com/in/coding-decoded-6809a3215/

  • @gauravshah7888
    @gauravshah7888 Жыл бұрын

    Thanks!

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    Жыл бұрын

    Thanks Gaurav

  • @comment.only0598
    @comment.only0598 Жыл бұрын

    Most youtuber explained this question like "Ratta". Thanks for this amazing video and explained very well.

  • @gaurabdas1510
    @gaurabdas1510 Жыл бұрын

    Great explanation!

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    Жыл бұрын

    Glad it was helpful!

  • @pareekshithachar3788
    @pareekshithachar3788 Жыл бұрын

    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

  • @user-fx5lk6dy3m

    @user-fx5lk6dy3m

    10 ай бұрын

    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.

  • @vishalratna89
    @vishalratna8911 ай бұрын

    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?

  • @mohithadiyal6083
    @mohithadiyal60832 жыл бұрын

    You are simply amazing 😁

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    2 жыл бұрын

    you too bro

  • @krishan7630
    @krishan7630 Жыл бұрын

    Thanks bro

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    Жыл бұрын

    Welcome

  • @mandy1339
    @mandy13392 жыл бұрын

    You are amazing!

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    2 жыл бұрын

    You too!!

  • @lingasodanapalli615
    @lingasodanapalli61510 ай бұрын

    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

  • @Sauravk2107
    @Sauravk2107 Жыл бұрын

    ver nice explanation

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    Жыл бұрын

    Thanks for liking

  • @jagdambesingh7293
    @jagdambesingh7293 Жыл бұрын

    Could you please explain why you have used loop inside while loop ,?

  • @umeshhbhat
    @umeshhbhat2 жыл бұрын

    Well explained man!

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    2 жыл бұрын

    Thanks Umesh, watch out the entire series you will simply love it

  • @umeshhbhat

    @umeshhbhat

    2 жыл бұрын

    @@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.

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    2 жыл бұрын

    @@umeshhbhat thanks for the tip man.. will come over video very soon

  • @girikgarg8
    @girikgarg82 жыл бұрын

    Time complexity of this approach?

  • @nicolattu
    @nicolattu2 жыл бұрын

    Nice one to know 👌👏 is it travelling salesman problem with unweighted edges? Also how can we calculate time complexity?

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    2 жыл бұрын

    Yes it is similar to that

  • @mandy1339

    @mandy1339

    2 жыл бұрын

    Yea it's a variation of travelling salesman.

  • @sahilattri51
    @sahilattri51 Жыл бұрын

    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?

  • @sahilattri51

    @sahilattri51

    Жыл бұрын

    My bad, understood the concept now. Thanks for the video.

  • @alldaysports6556
    @alldaysports65562 жыл бұрын

    how can we know where to use bit manipulation . i mean intuition to use bit??

  • @bloody9162

    @bloody9162

    2 жыл бұрын

    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.

  • @kshitijgarg2609
    @kshitijgarg260910 ай бұрын

    SOlid explanatory video

  • @vaibhavvashist238
    @vaibhavvashist2382 жыл бұрын

    is this question might come in interview as the level is question is little bit high?

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    2 жыл бұрын

    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

  • @dubeyanurag
    @dubeyanurag10 ай бұрын

    The BFS Solution is a lot more straightforward than the DFS one.

  • @gangstacoder4234
    @gangstacoder42344 ай бұрын

    isnt just knowing about the parent node enough to avoid indefinite loops

  • @bikideka7880
    @bikideka78802 жыл бұрын

    Hey is Leetcode hard necessary for interviews and online coding round?

  • @MrVrtex

    @MrVrtex

    10 ай бұрын

    For FAANG/MAANG yes

  • @Think_Code
    @Think_Code2 жыл бұрын

    a suggestion : u can use wacom tablet with pen to write instead of mouse. That will improve your efficiency. you can check mine videos.

  • @CodeWithSunchitDudeja

    @CodeWithSunchitDudeja

    2 жыл бұрын

    Thanks thinkcode for the advice

  • @ranitripathi607
    @ranitripathi6072 жыл бұрын

    prettiest 😢

  • @gauravshah7888
    @gauravshah7888 Жыл бұрын

    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

  • @HarshaKeVlogs

    @HarshaKeVlogs

    11 ай бұрын

    thank you

  • @HarshaKeVlogs

    @HarshaKeVlogs

    11 ай бұрын

    useful

  • @sonicjetson6253
    @sonicjetson625310 ай бұрын

    arre bhai jisne yeh ques pehle nahi dekha woh kaise solve karega interview main. total chutiyapa chal raha hain