Given a sorted Dictionary of an Alien Language, find order of characters | [Explaination + CODE] 🔥

Sdílet
Vložit
  • čas přidán 6. 09. 2024
  • #graph #competitiveprogramming #coding #dsa
    Hey Guys in this video I have explained with code how we can solve the problem 'Given a sorted Dictionary of an Alien Language, find order of characters'.
    Join our Telegram Channel for more Information
    🔰 Telegram Channel Link = t.me/CodeLibrary1
    🔰 Array question Playlist = • Love Babbar DSA 450 Qu...
    🔰 String question Playlist = • Love Babbar DSA 450 Qu...
    🔰 Searching and Sorting question Playlist = • Love Babbar DSA 450 Qu...
    🔰 Binary Tree question Playlist = • Love Babbar DSA 450 Qu...
    🔰 Dynamic Programming question Playlist = • Love Babbar DSA 450 Qu...
    🔰 RoadMap of Web Development = • 🔴 Web Development Road...
    🔰 Roadmap for Dynamic Programming = • Complete Roadmap for D...
    🔰 Great Strategy to solve DSA = • Great Strategy to solv...
    🔰 My Journey to 5 star at codechef = • My Journey to 5 Star a...
    🔰 Love Babbar DSA Sheet : drive.google.c...
    Follow us on Instagram:
    🔰 Shailesh Yogendra : / shaileshyogendra
    🔰 Yogesh Yogendra : / i_am_yogesh_here
    Follow us on LinkedIn:
    🔰 Yogesh Yogendra : / yogesh-yogendra-26bbb518a
    🔰 Shailesh Yogendra : / shailesh-yogendra-8b13...
    Hope you like it. Comment if you have any doubt
    LIKE | SHARE | SUBSCRIBE

Komentáře • 46

  • @PeaceLoveAman
    @PeaceLoveAman Před 3 lety +6

    bro digital drawing pad aata hai. Wo buy kar le, I'll be good for you to explain and write.

  • @ani68
    @ani68 Před 2 lety

    Great explanation...was trying to do this question since long

  • @purushottamkumar4056
    @purushottamkumar4056 Před 3 lety +4

    ba , dc
    Iska graph kaise bnega bhai , is code k hisab se to bs b->d hi create hoga , a or c ka kya hoga ?????

  • @kabyasharma1396
    @kabyasharma1396 Před 3 lety +3

    you explain brilliantly .

  • @himanshu2149
    @himanshu2149 Před 3 lety +1

    Excellent explanation!!

  • @ravulaakhilsurya8569
    @ravulaakhilsurya8569 Před 3 lety +1

    Toposort as to be start with a node with degree 0( means no incoming edge).....

    • @rishabsharma5307
      @rishabsharma5307 Před 3 lety +2

      We start with indegree 0 in BFS (Kahn's Algorithm) but in DFS you can start from anywhere

  • @apoorv7361
    @apoorv7361 Před 3 lety +7

    Great explanation brother! If possible please also provide a link to your source code!

  • @anuragkhanna9519
    @anuragkhanna9519 Před 2 lety

    thanks for explaining question so well

  • @pepetikesavasiddhardha7852

    nice explanation

  • @SalmanAnsariKSA
    @SalmanAnsariKSA Před 2 lety +1

    You are very hurry in a main coding part.
    How to approach that is very good explanation but you have to focus more deeply on code.

  • @rahulbanerjee9676
    @rahulbanerjee9676 Před 2 lety +2

    Your code is not working bro

  • @sanskarjain2730
    @sanskarjain2730 Před 3 lety +6

    Shouldn't we compare every pair of strings rather than just consecutive ones?

    • @saarthakaggarwal7018
      @saarthakaggarwal7018 Před 3 lety +2

      i have the same query that why are'nt we comparing all pairs? @CodeLibrary

    • @animatedzombie64
      @animatedzombie64 Před 3 lety +9

      the list is already sorted, so we could traverse through pair of words and build graph.

  • @himanshusingh2360
    @himanshusingh2360 Před 2 lety

    Great explanation

  • @tridevthakur7711
    @tridevthakur7711 Před 2 lety

    Plz make video on " Tarjans Algorithm for SCC"

  • @dsa3334
    @dsa3334 Před 3 lety

    Great Explanation

  • @susantakumardutta6283
    @susantakumardutta6283 Před 3 lety +1

    Hello bhaiya...I am writing the same code in java...but I am getting "IndexOutOfBoundException" error....please tell me how to solve this

    • @hardikralhan5962
      @hardikralhan5962 Před 2 lety

      class Solution2
      {
      public String ans = "";
      public String findOrder(String [] dict, int N, int K) {
      // Write your code here
      ArrayList graph = new ArrayList();
      for(int i = 0; i < K; i++) graph.add(new ArrayList());
      for(int i = 0; i < N -1; i++) {
      String wd1 = dict[i];
      String wd2 = dict[i + 1];
      for(int j = 0; j < Math.min(wd1.length(), wd2.length()); j++) {
      if(wd1.charAt(j) != wd2.charAt(j)) {
      graph.get(wd1.charAt(j) - 'a').add(wd2.charAt(j) - 'a');
      break;
      }
      }
      }
      boolean[] vis = new boolean[K];

      for(int i = 0; i < K; i++) {
      if(!vis[i]) dfs(i, graph, vis);
      }
      return ans;
      }
      public void dfs(int i, ArrayList graph, boolean[] vis) {
      vis[i] = true;
      for(int x : graph.get(i)) {
      if(!vis[x]) dfs(x, graph, vis);
      }
      char ch = (char)(i + 'a');
      ans = ch + ans;
      }

      }

  • @kushagrashukla4913
    @kushagrashukla4913 Před 2 lety +1

    This code is giving TLE.Please help

  • @nandinibagga4857
    @nandinibagga4857 Před 3 lety

    greaaaaaat explanation!

  • @0_0-0_0.
    @0_0-0_0. Před 2 lety

    What about this test case ?
    {"bac", "bad", "baefgh"}
    graph will look like : c -> d -> e
    and the topo sort is : c, d, e
    But where is f, g, h in the order ????
    HELP PLEASE !

    • @raunakkumar6144
      @raunakkumar6144 Před 2 lety +1

      did the question state that you need to tell order of all k char, not right.
      And this also depends on n and k like as in your test case k is 6 and n is only three so not possible to state order for all k, u need atlest k words if each specify the order of letter else you need more words.

    • @0_0-0_0.
      @0_0-0_0. Před 2 lety

      @@raunakkumar6144 Ohh! understood.
      Thank you so much for explain.

  • @pranayagarwal1380
    @pranayagarwal1380 Před 2 lety

    when using your solution, I am getting and in reverse. why?

  • @abhishekgupta3698
    @abhishekgupta3698 Před 3 lety +1

    Bhai graph g(k) ke liye vector of vector kyun liya ek se bhi kaam ho sakta hai na

    • @ankitdubey9310
      @ankitdubey9310 Před 2 lety +2

      nahi bhai , adjacenecy list hai na , har letter ke arrow pe kaun kaun hai wo to ek matrix ban jayega

    • @abhishekgupta3698
      @abhishekgupta3698 Před 2 lety

      @@ankitdubey9310 Thanks

  • @divyanshusen5916
    @divyanshusen5916 Před 3 lety

    Bhai ek bar kruksal aur prim's ki bhi video banado.It's difficult to understand code

  • @nishantmittal1506
    @nishantmittal1506 Před 2 lety +1

    Segmentation fault is coming

    • @nishantmittal1506
      @nishantmittal1506 Před 2 lety

      void dfs(int src,vector &g,vector &vis,string &ans)
      {
      vis[src] = 1;
      for(auto x:g[src])
      {
      if(!vis[x])
      {
      dfs(x,g,vis,ans);
      }
      }
      char ch = src + 'a';
      ans = ans + to_string(ch);
      }
      string findOrder(string dict[], int N, int k) {
      //code here
      vector g(k);
      for(int i=0;i

    • @rohankumarshah5679
      @rohankumarshah5679 Před 2 lety

      @@nishantmittal1506 return ans ;

    • @rahulbanerjee9676
      @rahulbanerjee9676 Před 2 lety

      @@nishantmittal1506 Still facing the same problem

    • @nishantmittal1506
      @nishantmittal1506 Před 2 lety

      @@rahulbanerjee9676 no bro ab tou placement bhi hogi

    • @raunakkumar6144
      @raunakkumar6144 Před 2 lety

      check your loop you must have been lopping it for n instead of n-1

  • @Prodcater
    @Prodcater Před 3 lety

    any one having code for this

  • @sanskarkumar7984
    @sanskarkumar7984 Před 3 lety +1

    Bhai Graph ke baad Start Bst please.

  • @akshyagarg2398
    @akshyagarg2398 Před 3 lety +2

    Believe me or not you guys explain much better than striver.