G-29. Word Ladder - I | Shortest Paths

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.พ. 2025
  • GfG-Problem Link: bit.ly/3PuJxk3
    C++/Java/Codes and Notes Link: takeuforward.o...
    DP Series: • Striver's Dynamic Prog...
    SDE Sheet: takeuforward.o...
    Check out our Website for curated resources:
    Our Second Channel: / @striver_79
    In case you are thinking to buy courses, please check below:
    Code "takeuforward" for 15% off at GFG: practice.geeks...
    Code "takeuforward" for 20% off on sys-design: get.interviewr...?_aff=takeuforward
    Crypto, I use the Wazirx app: wazirx.com/inv...
    Take 750 rs free Amazon Stock from me: indmoney.oneli...
    Earn 100 rs by making a Grow Account for investing: app.groww.in/v...
    Linkedin/Instagram/Telegram: linktr.ee/take...
    ---------------------------------------------------------------------------------------------------------------------------

ความคิดเห็น • 349

  • @takeUforward
    @takeUforward  2 ปีที่แล้ว +72

    Let's continue the habit of commenting “understood” if you got the entire video. Please give it a like too, you don't 😞
    Do follow me on Instagram: striver_79

  • @tanya8353
    @tanya8353 5 หลายเดือนก่อน +8

    The patience with which you do dry run is really commendable!!!!🔥

  • @topgunn6683
    @topgunn6683 2 ปีที่แล้ว +130

    Watching your lectures before the Google on-site interview

    • @harshdasila6680
      @harshdasila6680 2 ปีที่แล้ว +22

      if you got selected refer me too :)

    • @aryashjain7893
      @aryashjain7893 2 ปีที่แล้ว +7

      linkedln id dedo bhaiya XD

    • @gp7060
      @gp7060 2 ปีที่แล้ว +4

      I have my google on-site next month.. want to discuss on prep so can we connect on LinkedIn ?

    • @shyren_more
      @shyren_more ปีที่แล้ว +1

      how did it go?

    • @anonymousanonymous7507
      @anonymousanonymous7507 ปีที่แล้ว +1

      Ok Googler

  • @ayushpatel2171
    @ayushpatel2171 2 ปีที่แล้ว +180

    Honestly I feel that the hard part about this question was figuring out that it is a graph question. But since I was following the playlist I already knew that it is a graph question. Which is why upon looking the question the intuition came easily to me.

    • @ridj41
      @ridj41 ปีที่แล้ว +13

      naah since,src and dest pointers were there, it was easy to figure out it was a graph,but rest was difficult

    • @sahilbani7020
      @sahilbani7020 5 หลายเดือนก่อน +6

      How is this even a Graph problem?

    • @GauravKumar-xc4kr
      @GauravKumar-xc4kr หลายเดือนก่อน

      so us bro🫂🫂same thought

    • @sumit5639
      @sumit5639 หลายเดือนก่อน

      same thought

  • @gorilla_coder-el6kf
    @gorilla_coder-el6kf ปีที่แล้ว +5

    thank you striver i was able to solve this problem on my own because of your graph playlist. heartiful thanks for this playlist.this is the best out there.

  • @vaarigupta6332
    @vaarigupta6332 ปีที่แล้ว +20

    Instead of erasing the string from the set, you can take unordered_map and mark it as true which is generally used in BFS for marking visited nodes.

    • @infinityzero2321
      @infinityzero2321 ปีที่แล้ว +3

      ya but that will unnecessarily increase the space complexity

    • @jagannathan1014
      @jagannathan1014 ปีที่แล้ว +9

      Terrible idea as it not only increases SC , but also increases COLLISIONS leading to worst case in hashmap

    • @abhinavgupta7048
      @abhinavgupta7048 ปีที่แล้ว

      @@jagannathan1014 can you please elaborate why it is a terrible idea and how will it increase collisions

    • @imPriyansh77
      @imPriyansh77 8 หลายเดือนก่อน +1

      yeah you can do it too...

    • @Predator-pv7of
      @Predator-pv7of 6 หลายเดือนก่อน

      @@abhinavgupta7048 it is generally advised to not use unordered sets and maps, and due to collisions, the worst case time complexity to access elements becomes O(n)

  • @manasranjanmahapatra3729
    @manasranjanmahapatra3729 2 ปีที่แล้ว +44

    Understood. Graph is slightly tough, but you are making it easy for us thank you🤘.

  • @AryanJoshi_CS
    @AryanJoshi_CS 8 วันที่ผ่านมา

    NO OTHER GUY TEACHES WITH UR ENERGY AND ENTHUSIASM MAN!!!!!

  • @santanu29
    @santanu29 2 ปีที่แล้ว +2

    I remember this problem came in Leetcode daily in Feb 2022. Just copied the code and did not understand anything. One year later I understood the code. Thank you for the explanation.

    • @imPriyansh77
      @imPriyansh77 8 หลายเดือนก่อน +3

      excellent memory brother

  • @arjunjadhav6275
    @arjunjadhav6275 ปีที่แล้ว +2

    i just watched the logic you have used and i was able to write code by myself , Thanks..🙏

  • @mahipatel9672
    @mahipatel9672 5 หลายเดือนก่อน +1

    Happy Teacher's day to you. You have helped so many of us to get their DSA concepts right. Kudos to you and thanks a lot :)

  • @anshjain5673
    @anshjain5673 6 หลายเดือนก่อน +4

    I solved this question in the following way which gives me the time complexity of O(n*m). I basically created the graph using adj list method and performed normal BFS instead of checking words in the set after modifying each letter of word.
    class Solution {
    public:
    bool checkDiff(string a, string b){
    int ptr=0, count=0;
    while(ptr!=a.size()){
    if(a[ptr]==b[ptr]){
    ptr++;
    continue;
    }
    ptr++;
    count++;
    }
    return count==1;
    }
    int ladderLength(string beginWord, string endWord, vector& wordList) {
    wordList.insert(wordList.begin(), beginWord);
    int n = wordList.size();
    vector adj[n];
    //Create undirected graph
    for(int i=0; i

    • @pramukhjain1742
      @pramukhjain1742 5 หลายเดือนก่อน +1

      The graph creation will take time = (N^2)*M (where N is length of words array & M is length of longest word).

  • @aryashjain7893
    @aryashjain7893 2 ปีที่แล้ว +1

    Understood , a big fan of your zero typing errors !!!!! awesome video as always thank you sir ji

  • @youdummy5928
    @youdummy5928 10 วันที่ผ่านมา

    The way you ellaborated the hard problem felt super easy.

  • @pktk001
    @pktk001 2 ปีที่แล้ว +22

    For second time I was able to solve GFG hard problem on my own , such a nice teaching. Though I doubt if such approach would've hit, if it hadn't been a part of Graph series.

  • @kumarsaurav1818
    @kumarsaurav1818 2 หลายเดือนก่อน +2

    thanks striver for this content . i was able to solve this problem by own ,because the way you clear every concept

  • @QuantaBytes
    @QuantaBytes 2 ปีที่แล้ว +7

    Hey Striver !! Your Videos are reaallly really helpful, easy to understand, and hats off for your amazing work and efforts.

  • @cinime
    @cinime 2 ปีที่แล้ว +6

    Understood! What an excellent explanation as always, thank you very much!!

  • @aruna5869
    @aruna5869 ปีที่แล้ว +1

    Understood. You are brilliant in finding the suitable example to explain the algorithm....!! Thanks a lot🙌❤

  • @sam_55555
    @sam_55555 3 หลายเดือนก่อน

    Thank you so much Striver for explaining problems in a very understandable way. Kudos to you for achieving lot at a very young age in the world of Top-tech

  • @SumitKeshariMCS
    @SumitKeshariMCS 2 ปีที่แล้ว +17

    Bravo, amazing!!
    I was always afraid of this question. But you explained it sooooo well. Thanks a lot striver.

    • @sypher4735
      @sypher4735 2 ปีที่แล้ว +3

      Yeah, it came out to be very simple.

    • @harishchoudhary9662
      @harishchoudhary9662 2 ปีที่แล้ว +6

      It took me around one day to solve these question using my method but in the end it got TLE on leetcode and now after seeing the solution the questions seems easy.

  • @harshvaghani4283
    @harshvaghani4283 6 หลายเดือนก่อน

    You gave me the confidence of solving a leetcode hard! The step by step explanation is wonderful!!

  • @gugli28
    @gugli28 5 หลายเดือนก่อน +2

    Simple bruteForce can be : for each element(say "hit") in list, compare it with the all other elements. If the only 1 char varies that we can add as part of adjacency List of "hit" and so on.

  • @AyushMishra-b8w
    @AyushMishra-b8w ปีที่แล้ว

    you can make any difficult question way too easy. Just loved your teaching style .😊😊😊😊

  • @rajatsaraf237
    @rajatsaraf237 2 ปีที่แล้ว +4

    Thanks striver, Was able to solve it by myself although my approach was different from this,
    I considered every node has a edge to every other node and each edge has a weight equal to the difference b/w the 2 vertices(words)
    Then just used the shortest distance for an undirected graph using BFS algo

    • @arjunrai8126
      @arjunrai8126 2 ปีที่แล้ว

      By node you mean the words right

    • @rajatsaraf237
      @rajatsaraf237 2 ปีที่แล้ว

      @@arjunrai8126 yes

    • @arjunrai8126
      @arjunrai8126 2 ปีที่แล้ว

      @@rajatsaraf237 by difference bw the words you mean the number of positions where the chars are different , right? Great solution

    • @rajatsaraf237
      @rajatsaraf237 2 ปีที่แล้ว

      @@arjunrai8126 yes, that char difference can be considered as the weight b/w two words

    • @rishabhinc2936
      @rishabhinc2936 ปีที่แล้ว +1

      W bro

  • @manasvinsharma1740
    @manasvinsharma1740 ปีที่แล้ว +9

    One more approach can be making the graph first & then finding the shortest path in it. We can make a graph where there will be a edge between all those nodes who differ by only 1 character. The graph creation will take time = (N^2)*M (where N is length of words array & M is length of longest word). Once graph is made we can apply BFS & also handle the case where target cannot reach.

    • @abhisheksen7990
      @abhisheksen7990 ปีที่แล้ว +1

      I was thinking the same way

    • @jyothiyadav2595
      @jyothiyadav2595 ปีที่แล้ว

      i tried this but it says tle??
      class Solution(object):
      def ladderLength(self, beginWord, endWord, wordList):
      """
      :type beginWord: str
      :type endWord: str
      :type wordList: List[str]
      :rtype: int
      """
      def issimilar(s1,s2):
      if len(s1)!=len(s2):
      return False
      l=len(s1)
      flag=True
      for i in range(l):
      if s1[i]!=s2[i] and flag==False:
      return False
      if s1[i]!=s2[i]:
      flag=False
      return True
      if endWord in wordList:
      final=wordList.index(endWord)
      que=[]

      n=len(wordList)
      adj=[[] for _ in range(n)]
      visited=[0 for _ in range(n)]
      for i in range(n-1):
      for j in range(1,n):
      if issimilar(wordList[i],wordList[j]):
      adj[i].append(j)
      adj[j].append(i)
      for i in range(n):
      if issimilar(wordList[i],beginWord):
      que.append((i,2))
      visited[i]=1


      while que:
      v,dis=que.pop(0)
      if v==final:
      return dis
      for i in adj[v]:
      if visited[i]==0:
      que.append((i,dis+1))
      visited[i]=1
      return 0


      can someone help??

    • @shujauddinsiddiqui8923
      @shujauddinsiddiqui8923 2 หลายเดือนก่อน

      @@jyothiyadav2595
      also created the graph first and it worked for me
      class Solution {
      class Pair {
      int n, d;
      Pair(int n ,int d) {
      this.n = n;
      this.d = d;
      }
      }
      boolean check(String st1, String st2) {
      int c=0;
      for(int i=0; i

  • @tanujaSangwan
    @tanujaSangwan 5 หลายเดือนก่อน +2

    My approach is different: This can be visualised as an undirected weighted graph with unit weights. We can created graph with word as each node and all neighbours are the words with only one character changed. Then apply exact same BFS as we implement in the previous video. No code changes at all. Quite simple and passes all testcases.
    bool isAdjacent(const string& word1, const string& word2) {
    int diff = 0;
    for (int i = 0; i < word1.size(); ++i) {
    if (word1[i] != word2[i]) {
    diff++;
    if (diff > 1) return false;
    }
    }
    return diff == 1;
    }
    // Function to create the adjacency list graph
    unordered_map buildGraph(vector& wordList) {
    unordered_map graph;
    // Add an empty list for each word
    for (const string& word : wordList) {
    graph[word] = {};
    }
    // Connect each word with its adjacent words
    for (int i = 0; i < wordList.size(); ++i) {
    for (int j = i + 1; j < wordList.size(); ++j) {
    if (isAdjacent(wordList[i], wordList[j])) {
    graph[wordList[i]].push_back(wordList[j]);
    graph[wordList[j]].push_back(wordList[i]);
    }
    }
    }
    return graph;
    }
    int wordLadderLength(string startWord, string targetWord, vector& wordList) {
    // If targetWord is not in the wordList, no valid transformation is possible
    if (find(wordList.begin(), wordList.end(), targetWord) == wordList.end()) {
    return 0;
    }
    // Include the startWord in the word list if it's not already there
    if (find(wordList.begin(), wordList.end(), startWord) == wordList.end()) {
    wordList.push_back(startWord);
    }
    // Build the graph from the word list
    unordered_map graph = buildGraph(wordList);
    // Perform BFS to find the shortest path
    unordered_map distance;
    for (const string& word : wordList) {
    distance[word] = INT_MAX; // Initialize distances with infinity
    }
    distance[startWord] = 1;
    queue q;
    q.push(startWord);
    while (!q.empty()) {
    string currentWord = q.front();
    q.pop();
    // Traverse all neighbors of the current word
    for (const string& neighbor : graph[currentWord]) {
    if (distance[neighbor] == INT_MAX) { // If not visited
    distance[neighbor] = distance[currentWord] + 1;
    q.push(neighbor);
    // If we reach the target word, return the distance
    if (neighbor == targetWord) {
    return distance[neighbor];
    }
    }
    }
    }
    // If BFS completes without finding the targetWord, return 0
    return 0;
    }

    • @manjotsingh8157
      @manjotsingh8157 5 หลายเดือนก่อน +2

      can u share the code?

    • @divyareddy7622
      @divyareddy7622 3 หลายเดือนก่อน +1

      love it, just higher time complexity while building the graph--can go up to N^2

    • @tanujaSangwan
      @tanujaSangwan 3 หลายเดือนก่อน

      @@divyareddy7622 yeah

  • @mriduljain6809
    @mriduljain6809 ปีที่แล้ว +1

    Was able to solve the problem on my own only because of you...Thank U😊😊
    Understood Bhaiya..

  • @anandkalpe2155
    @anandkalpe2155 2 ปีที่แล้ว +4

    Hey @striver this solution is exceeding time limit in leetcode, so instead of assigning all letter from a-z , I tried with letters only in wordList and it worked.
    I just added below function to get all the letters into vector-
    private:
    vector letters(vector&wordList){
    unordered_set st;
    vector result;
    for(auto it: wordList){
    for(int i=0;i

    • @subratkumar7359
      @subratkumar7359 2 ปีที่แล้ว +3

      I wrote the same code and it didn't give TLE.

  • @KratosProton
    @KratosProton 2 ปีที่แล้ว +3

    Understood, quality content!

  • @niteshbaith6350
    @niteshbaith6350 2 หลายเดือนก่อน

    Your explanation is brilliant, bro!!

  • @stith_pragya
    @stith_pragya ปีที่แล้ว +2

    Thank You So Much for this wonderful video..........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @parallax8916
    @parallax8916 ปีที่แล้ว +2

    Briliiantly explained
    When I read the question for the first time, I was so scared and I had no clue how to proceed.
    I was thing of sets and recursion but I did not even try coz Iwas scared.
    But u made it soo simple that after watching half of the video, I did it in 1 go .
    U r amazing striver.
    please continue to bring such playlists , its so helpful

    • @imPriyansh77
      @imPriyansh77 8 หลายเดือนก่อน

      were you thinking about backtracking too in first go?

  • @_lifestylefusion
    @_lifestylefusion 9 หลายเดือนก่อน

    Very clear explanation. Hats off to your effort .

  • @senvikas1946
    @senvikas1946 2 ปีที่แล้ว

    I did like and kya hi samjhate ho yrr bhaiya, maza hi aa gaya. UNDERSTOOD

  • @Engineer_Padai
    @Engineer_Padai 2 ปีที่แล้ว +2

    thanks striver bhai, for this awesome series

  • @anshukumari6226
    @anshukumari6226 หลายเดือนก่อน

    Great explanation, Raj

  • @yasaswinikarumuri9590
    @yasaswinikarumuri9590 2 ปีที่แล้ว +1

    Such a great explanation! Please continue the playlist

  • @Sara-ed3jq
    @Sara-ed3jq ปีที่แล้ว

    Best series on graph

  • @sukhpreetsingh5200
    @sukhpreetsingh5200 2 ปีที่แล้ว +2

    excellent explanation as always, thank you very much!! Amazing playlist

  • @vatsalvasoya5243
    @vatsalvasoya5243 ปีที่แล้ว +1

    Understood!! Very well explained!!!

  • @techatnyc7320
    @techatnyc7320 5 หลายเดือนก่อน

    Great work, Raj!

  • @ITSuyashTiwari
    @ITSuyashTiwari 3 หลายเดือนก่อน

    your explanation made it too easy🤗

  • @harleenkaur7751
    @harleenkaur7751 2 ปีที่แล้ว +2

    Thanks a lot, Striver. Best explanation . 😀

  • @giteshkhanna2633
    @giteshkhanna2633 2 หลายเดือนก่อน

    Since its bfs, steps are going to be common for each level traversal. So no need to save the steps inside queue. Can maintain it outside & keep incrementing as we finish one traversal.

  • @studynewthings1727
    @studynewthings1727 9 หลายเดือนก่อน

    understood. Able to write the code by myself after getting the intuition.

  • @pratikshadhole6694
    @pratikshadhole6694 2 ปีที่แล้ว +1

    GOAT❤ you are great striver

  • @ashutoshgiri2974
    @ashutoshgiri2974 19 วันที่ผ่านมา

    some explanation maza aa gya❤

  • @harshdiwase1941
    @harshdiwase1941 7 หลายเดือนก่อน

    this question was amazing , thanks striver

  • @Health_asset
    @Health_asset ปีที่แล้ว

    best method to solve this question 😁thanks striver
    I got your algo and tried myself , just make a little mistake but it was corrected bcoz of your code

  • @kaichang8186
    @kaichang8186 5 หลายเดือนก่อน

    understood, thanks for the detail explanation

  • @amanasrani6405
    @amanasrani6405 9 หลายเดือนก่อน

    yours HArdwork is really ❤

  • @user-rf3he9uv5m
    @user-rf3he9uv5m ปีที่แล้ว

    UNDERSTOOD striver!

  • @rishavkumar2182
    @rishavkumar2182 2 ปีที่แล้ว +2

    great explanation!!

  • @1tav0
    @1tav0 2 ปีที่แล้ว +2

    understood! amazing like always.

  • @deepakagrawal7687
    @deepakagrawal7687 ปีที่แล้ว +2

    we can create graph from the word list and do topological sort on it. that will give only limited characters that exists in word list and we can try out replacing characters present in word list only. with topological sort the we get array as h,d,l,c,o,t,g.
    Now I know before o I have 4 characters to try for first place i.e. h,d,l,c. then for g I have 2 characters o and t
    with same BFS algoritm we can avoid trying out all a-z combination and also it makes sense logically because after transformation if word should be from word list then try out with characters that are only in wordlist. if z is not present in wordlist in any word why to try out with that. Considering if there is no cycle in it. This needs to be asked to interviewer whether there will be cycle in the graph. If cycle exists then the other approach is to iterate through all the wordlist and put them in set. Atleast you will be comparing less characters then a-z

  • @urstrulyjatin
    @urstrulyjatin 2 หลายเดือนก่อน

    Meeri jhann!! understood!

  • @anchaldevrani2055
    @anchaldevrani2055 ปีที่แล้ว +1

    Understood 🎉

  • @shreycpaunwala1420
    @shreycpaunwala1420 7 หลายเดือนก่อน +1

    Hey Striver! Understood the concept thoroughly. Had one doubt, my first intuition was to use DP in this question instead of graph. SO why graph is more optimal then dp?

    • @brokegod5871
      @brokegod5871 6 หลายเดือนก่อน +1

      1) The question has a source to destination pattern, it's guiding you a path that you start from this word and end somewhere... This intends graph... Also they are saying "shortest" while giving you source and destination so you should think of shortest path algorithm
      2) Reason why you thought of Recursion/DP is because we are trying every letter combination which is fair to think but you apply DP when you have a vast search space and you have no clue which can be the answer but here they've given you the dictionary list so they are telling you the search space

  • @vikas7588
    @vikas7588 6 หลายเดือนก่อน

    It's a high time youtube should add a super like button.

  • @GoodLuck-dv2zu
    @GoodLuck-dv2zu 2 ปีที่แล้ว +1

    As always AMAZING!

  • @raghavmanish24
    @raghavmanish24 9 หลายเดือนก่อน

    thnaku striver ...you are making my carrir

  • @sherlockholmes1605
    @sherlockholmes1605 2 ปีที่แล้ว

    Amazing explanation and logic! kuch bhi bolo, Striver bhai is built different!

  • @Amitkumar-nk5mo
    @Amitkumar-nk5mo ปีที่แล้ว

    understood....your explainations are lucid ....keep up the good work...

  • @breakthecode8323
    @breakthecode8323 2 ปีที่แล้ว +2

    Striver, thank you so much for graph series, per please can you also make series on segement trees, tried learning from so many places, but nowhere satisfactory content is found, bana do na ek series please

  • @DharnaMittal-vz9fi
    @DharnaMittal-vz9fi 7 หลายเดือนก่อน

    Striver you are the best

  • @rushikeshg25
    @rushikeshg25 2 ปีที่แล้ว +1

    Thank you for such a wonderful Explanation !!!!

  • @disciplines4
    @disciplines4 ปีที่แล้ว

    thanks striver for such wonderful explanation.

  • @psydook
    @psydook 6 หลายเดือนก่อน

    once i knew it was a graph question, i tried this myself :
    class Solution {
    private:
    bool check(const string& w1, const string& w2) {
    int differences = 0;
    for (int i = 0; i < w1.length(); ++i) {
    if (w1[i] != w2[i]) {
    differences++;
    if (differences > 1) return false;
    }
    }
    return true;
    }
    public:
    int ladderLength(string beginWord, string endWord, vector& wordList) {
    bool possible = false;
    int index = -1;
    for (int i = 0; i < wordList.size(); i++) {
    if (wordList[i] == endWord) {
    index = i;
    possible = true;
    break;
    }
    }
    if (!possible) return 0;

    wordList.insert(wordList.begin(), beginWord);
    int n = wordList.size();
    vector adj(n);
    for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
    if (check(wordList[i], wordList[j])) {
    adj[i].push_back(j);
    adj[j].push_back(i);
    }
    }
    }
    vector distance(n, INT_MAX);
    queue q;
    q.push({0, 0});
    distance[0] = 0;
    while (!q.empty()) {
    int node = q.front().first;
    int dist = q.front().second;
    q.pop();
    for (int val : adj[node]) {
    if (distance[val] > dist + 1) {
    distance[val] = dist + 1;
    q.push({val, dist + 1});
    }
    }
    }
    if (distance[index + 1] < INT_MAX) return distance[index + 1] + 1;
    return 0;
    }
    };

  • @LBK3
    @LBK3 ปีที่แล้ว +1

    understood ❤

  • @pradhuman_ramawat
    @pradhuman_ramawat ปีที่แล้ว +2

    I have a different solution, i created a graph representation using adjacency list (word is the key, words it can transform into are list values), then applied shortest distance method using dijkstra's algorithm.

    • @AnushkaVijay-cv7tk
      @AnushkaVijay-cv7tk ปีที่แล้ว

      can u please share your code....im having difficulty in making adjacency list

  • @GM-rw5fl
    @GM-rw5fl 2 ปีที่แล้ว

    How u make the hard question like a cake work amazing brother ......

  • @yashveernathawat8154
    @yashveernathawat8154 8 หลายเดือนก่อน

    For string set.find() method takes O(N) instead of logn.... It increases the complexity

  • @2000UK-v8c
    @2000UK-v8c 8 หลายเดือนก่อน

    Kudos to you sir!!

  • @abhishek__anand__
    @abhishek__anand__ ปีที่แล้ว

    Nicely Explained

  • @shailesh_rajpurohit
    @shailesh_rajpurohit ปีที่แล้ว +1

    14:36 Odissshhhaa

  • @imPriyansh77
    @imPriyansh77 8 หลายเดือนก่อน

    One can figure out that it was a graph question by looking at src & dest strings, & shortest sequence of transformations were asked...So, some 'feeling' of shortest path from src (beginWord) to dest (endWord) comes...

  • @_hulk748
    @_hulk748 ปีที่แล้ว

    Understood sir thankyou sir❤🙏🙇‍♂️

  • @aditikumari8204
    @aditikumari8204 2 ปีที่แล้ว +1

    understood..thanks bhaiya

  • @adebisisheriff159
    @adebisisheriff159 ปีที่แล้ว

    Thanks Strivers!!!!

  • @sambhavagarwal5871
    @sambhavagarwal5871 2 ปีที่แล้ว +2

    Understood! What an excellent explanation as always, thank you very much!! Amazing playlist thanks striver is this playlist is completed or not please confirm

  • @nagame859
    @nagame859 ปีที่แล้ว

    really don't understand why this is marked as "hard", this is one of the easiest problems, and it can also be considered as tree too.. regardless.. thank you Striver❤

  • @janhavibhosale1252
    @janhavibhosale1252 2 ปีที่แล้ว

    understood striver 🙌

  • @nisanduathsara5242
    @nisanduathsara5242 11 หลายเดือนก่อน

    fabulous striverrr

  • @NaveensinglaYT
    @NaveensinglaYT 2 ปีที่แล้ว

    amazing explanation bhai 🤩🤩🤩🤩

  • @mohammadkaif8143
    @mohammadkaif8143 ปีที่แล้ว

    Hi, awesome video. Just add one base condition to handle this case, according to your code it will give 1 but it should return 0..
    1
    der
    der
    der

  • @nirupamkumar6760
    @nirupamkumar6760 ปีที่แล้ว

    very nice explanation

  • @ksvijayan06
    @ksvijayan06 9 หลายเดือนก่อน

    Watching your lecture before the Meta phone screen round

  • @gauravgupta7280
    @gauravgupta7280 2 หลายเดือนก่อน

    A Small Optimization Can be MADE further ...
    So currently, for each index of the string we are traversing 26 times representing 26 characters / alphabets in the English Dictionary. But what if we exactly store the possible set of characters that are only available in wordList.
    There comes the optimization where we store set of all alphabets for each index & always iterate those in the while loop of queue.

  • @KratosProton
    @KratosProton 2 ปีที่แล้ว

    Great explaination

  • @ayushmaanpandey5233
    @ayushmaanpandey5233 7 หลายเดือนก่อน

    one doubt : why don't we replace the char of the word string with the respective char withthe same index of string present in the set, not from the 26 alphabet???.it will save time if give wordlist length is less than 26 otherwise above code is okay

  • @akshatsharma_iiti
    @akshatsharma_iiti 5 หลายเดือนก่อน

    sir ji 4:56 dream 💌

  • @amansingh.h716
    @amansingh.h716 5 หลายเดือนก่อน +2

    We converted DFS TO BFS😅😅

  • @rajsekhardutta8891
    @rajsekhardutta8891 2 ปีที่แล้ว

    Understood! 🤩❤‍🔥

  • @parshchoradia9909
    @parshchoradia9909 ปีที่แล้ว

    Understood Sir!

  • @empvaibhav9799
    @empvaibhav9799 7 หลายเดือนก่อน

    Instead of converting str to all the possible strings
    we can simply compare str with all the strings in word_List and see if the difference btw them is 1 or less and if so then add in queue to do BFS.

  • @rushidesai2836
    @rushidesai2836 7 หลายเดือนก่อน

    So damn good problem!

  • @MMNayem-dq4kd
    @MMNayem-dq4kd ปีที่แล้ว

    Understood,sir.

  • @niharikakumar1533
    @niharikakumar1533 ปีที่แล้ว

    Understood 👍🏻

  • @anujvishwakarma352
    @anujvishwakarma352 หลายเดือนก่อน

    Why are we checking for each alphabet for each character of a word. can we check for letters which can form any word in the list.