All Path From Source To Target 🔥 | Leetcode Graph solution DFS Hindi explained Complete Graph Videos

Поділитися
Вставка
  • Опубліковано 11 жов 2024

КОМЕНТАРІ • 78

  • @parthlodhia5974
    @parthlodhia5974 Рік тому +1

    Hey Prince, Awesome explanation.
    I got stuck at popping back the path vector, i didn't get an idea of popping path vector.
    But after your explanation, i solved it easily with DFS.
    Thank you.

    • @HelloWorldbyprince
      @HelloWorldbyprince  Рік тому

      Great 👍
      Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀

  • @codewith_ayushluthra5248
    @codewith_ayushluthra5248 Рік тому +1

    ajj ferse bhai tumhare video dekh ke motivation itne milte hai ke video ko ajj 27 sec dekha fer kudh solve karleya . Thanks

  • @VinayListenMe
    @VinayListenMe 9 місяців тому

    Great explanation, good thing is you never added unnecessary Boolean visited array as this is DAG graph so no possibility of any cycle hence Boolean array is not required.

  • @Ramneet04
    @Ramneet04 Рік тому

    I have seen all your playlist except dynamic programming, will complete it after the graph one, you're teaching way is so good,well mannered structured playlist, bless you.thx a lot bhaiyaa.

  • @Shadowishperz
    @Shadowishperz Рік тому

    Simplest explanantion , it would be more helpful if we discuss about time complexity towards the end of all problem videos

  • @heerasingh3308
    @heerasingh3308 Рік тому

    I have solved the question in 40 minutes, without watching your video, when you say, try yourself, then I will watch your logic, thank you :)

  • @abhishekpaul8515
    @abhishekpaul8515 Рік тому +2

    The way you explained made it so simple! Amazing 🔥

  • @parthstark2934
    @parthstark2934 2 роки тому

    Bhaiya attempt kiya, accepted! because of you, now watching your video for further knowledge. Thanks

    • @HelloWorldbyprince
      @HelloWorldbyprince  2 роки тому

      Wahhh bro good Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀

  • @im_ykp
    @im_ykp 2 місяці тому

    Thank You for motivating me to give it a try.

  • @shubhamkumar6383
    @shubhamkumar6383 Рік тому +1

    1st question i solve it by myself felt amazing !!!
    class Solution {
    public:
    void solve(unordered_map adj , int curr , vector &res , vector tmp , int n , vector &vis ){
    vis[curr] = 1;
    tmp.push_back(curr);
    if(n-1 == curr)
    res.push_back(tmp);
    for(auto k : adj[curr]){
    if(!vis[k])
    solve(adj,k,res,tmp,n,vis);
    }
    vis[curr] = 0;
    }
    vector allPathsSourceTarget(vector& graph) {
    vector res;
    unordered_map adj;
    int n = graph.size();
    vector vis(n,0);
    for(int i=0 ; i < n ; i++){
    for(auto k : graph[i])
    adj[i].push_back(k);
    }
    vector tmp;
    solve(adj,0,res,tmp,n,vis);
    return res;
    }
    };

  • @shashwatrao6949
    @shashwatrao6949 2 роки тому

    I solved it by myself just because of ur explanations. Thnx brother

  • @surajhengne4633
    @surajhengne4633 Рік тому

    Is it possible to solve above problem using BFS ? The solution you showed here is not optimal too many recursive call if your graph is too large.

  • @mayankchoudhary7937
    @mayankchoudhary7937 Рік тому

    i solve it by myself thanks to you :)

  • @muskangupta2545
    @muskangupta2545 2 роки тому +2

    Thanks.. amazing explanation
    Suggestion- Please add the complexity analysis also in videos

    • @HelloWorldbyprince
      @HelloWorldbyprince  2 роки тому +2

      sure muskan
      Please , if possible then share this channel in your college, groups or linkedin becoz it's cost nothing to you 😀

    • @muskangupta5873
      @muskangupta5873 2 роки тому +1

      @@HelloWorldbyprince sure I will share it

  • @pritishpattnaik4674
    @pritishpattnaik4674 2 роки тому

    mast laga approach , i was able to find my mistakes

  • @graphian8990
    @graphian8990 Рік тому

    Bhaiya graph[curr] ek vector ho then how can x can be pass to curr which is int .as curr is int and x is a vector

  • @gauravkesarwani7925
    @gauravkesarwani7925 Рік тому

    bhaiya what if there is cycle in between source and destination and then will get stuck their and never reach out destination

  • @abhisheksamboddu6580
    @abhisheksamboddu6580 2 роки тому +1

    reached milestone of 50 probs on leetcode .....with this ....started a month ago

  • @rohansaraswat3740
    @rohansaraswat3740 2 роки тому

    Thanks for the playlist, I was able to solve this Question by myself.

  • @eduflex7931
    @eduflex7931 2 роки тому +1

    Bhaiya dfs me to visited array bhi lete ,ye recursion wala approach haina?

    • @tarunkumar-kz5xi
      @tarunkumar-kz5xi 2 роки тому +1

      wo hame cycle me jane se avoid karne ke liye hoti isme DAG diya h problem statement me isliye calculate kar pa rahe h without visited array

  • @rahadarafin9052
    @rahadarafin9052 2 місяці тому

    playlist show 238 videos but we can find 200 videos.please tell me why you hide 38 videos? Those was alien types videos or google exam future questions was?

  • @feminabrahmbhatt5430
    @feminabrahmbhatt5430 6 місяців тому

    can you also explain krushkal algorithm ?

  • @monkiitianiitg9349
    @monkiitianiitg9349 2 роки тому

    Thanks.. amazing explanation

  • @harsimran.27
    @harsimran.27 2 роки тому +1

    Nice explanation bhaiya 😊👍🏻👍🏻

  • @PankajKumar-tg5zi
    @PankajKumar-tg5zi Рік тому

    maza agaya bhaiya

  • @bokhiriyakhushalinagajanbh7019
    @bokhiriyakhushalinagajanbh7019 2 роки тому

    what will be the space complexity for this All Paths From Source to Target question?

  • @atifhu
    @atifhu Рік тому +1

    you should have explained TC also

    • @HelloWorldbyprince
      @HelloWorldbyprince  Рік тому

      is same as DFS

    • @atifhu
      @atifhu Рік тому +1

      @@HelloWorldbyprince no sir, it's exponential, but I didn't get it how

  • @tarunkumarjoshi431
    @tarunkumarjoshi431 2 роки тому +1

    Bhaiya what are you doing is really great i am really inspired by you the hard work you do for us .

    • @HelloWorldbyprince
      @HelloWorldbyprince  2 роки тому +1

      Thanks bhai
      Bass share kardo channel ko mere motivation ke liye

  • @pranavkorhale5089
    @pranavkorhale5089 2 роки тому +1

    //Java Solution
    class Solution {
    public List ans = new ArrayList();
    public List allPathsSourceTarget(int[][] graph) {
    int n = graph.length;

    //[[4,3,1],[3,2,4],[],[4],[]]

    int start = 0;
    int end = n-1;

    int arr[] = graph[start];

    boolean[]visited = new boolean[n];
    visited[start] = true;

    List al = new ArrayList();
    al.add(start);

    for(int i=0;i

    • @HelloWorldbyprince
      @HelloWorldbyprince  2 роки тому

      amazing bro keep it up

    • @smilenpassion
      @smilenpassion Рік тому

      I think we don't need visited array:
      class Solution {
      public List allPathsSourceTarget(int[][] graph) {
      List result= new ArrayList();
      List path= new ArrayList();

      dfs(graph, result, path, 0);
      return result;
      }

      void dfs(int [][] graph, List result, List path, int src ){
      path.add(src);
      if(src==graph.length-1){
      result.add(new ArrayList(path));

      }

      for(int nei: graph[src]){
      dfs(graph, result, path,nei);
      }
      path.remove(path.size()-1);
      }

  • @anonymous090
    @anonymous090 2 роки тому

    Great vid!😀

  • @easylearning6647
    @easylearning6647 Рік тому

    thank you bhai

  • @rahulchoudhary29
    @rahulchoudhary29 Рік тому

    C++ solution
    class Solution {
    public:
    void dfs(int src,int dest,vector& graph,vector currentPath,vector &res){
    currentPath.push_back(src);
    if(src==dest) {
    res.push_back(currentPath);
    return;
    }
    for(auto it : graph[src]){
    dfs(it,dest,graph,currentPath,res);
    }

    }
    vector allPathsSourceTarget(vector& graph) {
    vector res;
    vector currentPath;
    int n=graph.size();
    dfs(0,n-1,graph,currentPath,res);
    return res;
    }
    };

  • @brijeshkumarverma1223
    @brijeshkumarverma1223 Рік тому

    1:17

  • @DeepakKumar-oz5ky
    @DeepakKumar-oz5ky 3 місяці тому

    maja aaya bhaiya

  • @a036nikhilsannat4
    @a036nikhilsannat4 2 роки тому +1

    Why we don't have visited dict?

    • @HelloWorldbyprince
      @HelloWorldbyprince  2 роки тому

      Issme jarurat nahi padda
      Aap chahaho to banaa sakte the

    • @jamespeterson7824
      @jamespeterson7824 2 роки тому

      It is directed acyclic graph..hence no need of visited..as we use visited so that it doesn't go in infinite loop.

  • @akankshagupta2946
    @akankshagupta2946 2 роки тому

    Nice vedio

  • @vitaminprotein2217
    @vitaminprotein2217 Рік тому

    it must be specified in q that all are connected components :/

    • @harshbhansali1327
      @harshbhansali1327 Рік тому

      and this solution is possible only because it is acyclic, if there are cycles then we would need visited array

  • @anuragdeol9474
    @anuragdeol9474 Рік тому

    Can anyone please tell the time and space complexity of this solution?

  • @Deepakkumar-mt1ep
    @Deepakkumar-mt1ep 2 роки тому

    can u help me
    i am not able to solve the question

    • @HelloWorldbyprince
      @HelloWorldbyprince  2 роки тому

      can u send me your code, or can u please try to dry run my code

  • @gauravkumar6632
    @gauravkumar6632 2 роки тому

    can you share solution in java

  • @thegreekgoat98
    @thegreekgoat98 2 роки тому

    Idhar adjacancy list ki kyun jarurat nahi padi?

  • @Deepakkumar-mt1ep
    @Deepakkumar-mt1ep 2 роки тому

    bhaiya i need help

  • @rahulgautam6387
    @rahulgautam6387 2 роки тому

    Great expla....