Word Ladder Leetcode optimised 2 solutions c++ code and explanation

Sdílet
Vložit
  • čas přidán 6. 09. 2024
  • A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord
    Every adjacent pair of words differs by a single letter.
    Every si is in wordList. Note that beginWord does not need to be in wordList.
    sk == endWord
    Given two words, beginWord and endWord, and a dictionary wordList, return the number of words in the shortest transformation sequence from beginWord to endWord, or 0 if no such sequence exists.

Komentáře • 24

  • @nehasht2
    @nehasht2 Před 2 lety +11

    First thing when I come across questions ..I go through your playlist if not found then search elsewhere.....I really appreciate the way you explain

  • @K-IT-VishalPanchal
    @K-IT-VishalPanchal Před rokem

    your explanation is amazing mostly your way to explain code with the help of example
    ✌✌

  • @shalsteven
    @shalsteven Před 7 měsíci

    THANK YOU so much for your clear and DETAIL explanation!

  • @amangaur4231
    @amangaur4231 Před rokem

    Too good 🔥 explaination....clearly understood 👍👍

  • @sachinsacse
    @sachinsacse Před 10 měsíci

    Nice explaination...
    BeginWord could be added to vector at starting itself before creating Adj list

  • @NaveenKumar-os8dv
    @NaveenKumar-os8dv Před 2 lety

    thank you, as always your explanation is great!

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

    Keep it up ma'am ❤️❤️

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

    Your explanation to good.

  • @vatsaldoshi7282
    @vatsaldoshi7282 Před 2 lety

    Nice explanation! Thanks

  • @Idukhan-jj9kc
    @Idukhan-jj9kc Před 2 lety

    Nice explanation alli

  • @aryannagraj4681
    @aryannagraj4681 Před 2 lety

    you explain very well

  • @rachitbadoni5717
    @rachitbadoni5717 Před 2 lety

    Nice explanation Di❤

  • @dhananjoydey1337
    @dhananjoydey1337 Před 2 lety

    thank you so much

  • @AmanSharma-vb5jl
    @AmanSharma-vb5jl Před rokem

    Thanks

  • @MilindGupta
    @MilindGupta Před 2 lety

    Hey alisha cover some dp questions too if possible

  • @ash11music
    @ash11music Před rokem

    can someone explain why time complexity is O(m*m*n) and not O(m*n) ?? it seems there are only 2 nested loops right?

    • @GojoSaturo-qe7uo
      @GojoSaturo-qe7uo Před 11 měsíci

      (first loop -> n)*( second loop -> m)*( diff function is called (which traverse the word)-> size of word)
      n*m* size of word

  • @shyren_more
    @shyren_more Před 2 lety

    great explanation, could you please share the code?

  • @HarendraKumar-yr4gt
    @HarendraKumar-yr4gt Před 2 lety

    😍😍

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

    if possible, can you please share your code

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

      class Solution {
      public:
      int ladderLength(string beginWord, string endWord, vector& wordList) {
      if (count(wordList.begin(), wordList.end(), endWord) == 0) return 0;
      unordered_set Set;
      queue Queue;
      unordered_map Map;
      wordList.push_back(beginWord);
      int N = wordList.size(), M = beginWord.size();
      for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
      string x = wordList[i].substr(0, j) + '*' + wordList[i].substr(j + 1, M - j - 1);
      Map[x].push_back(wordList[i]);
      }
      }
      Queue.push({beginWord, 1});
      while (!Queue.empty()) {
      pair P = Queue.front();
      Queue.pop();
      for (int j = 0; j < M; j++) {
      string x = P.first.substr(0, j) + '*' + P.first.substr(j + 1, M - j - 1);
      for (string &word: Map[x]) {
      if (Set.find(word) != Set.end()) continue;
      if (word == endWord) return P.second + 1;
      Queue.push({word, P.second + 1});
      Set.insert(word);
      }
      }
      }
      return 0;
      }
      };

  • @mahboobbiswas1304
    @mahboobbiswas1304 Před 2 lety

    hello, can you make videos for DSA?
    how can contact you?