Word Ladder | Leetcode

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ก.ย. 2024

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

  • @chiragmali6752
    @chiragmali6752 4 ปีที่แล้ว +21

    Very well explained. but there is one issue in 2 min 12 sec the path of length 7 is wrong. you have changed two chars instead of 1, while transforming "lot" to "dog".

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

      Yea. I did that in graph and I have flagged a correction there.

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

      @@techdose4u Cool.. keep it up!!

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว

      @@chiragmali6752 thanks :)

  • @shubhamkhurana7545
    @shubhamkhurana7545 4 ปีที่แล้ว +76

    Hey Man, I got placed today at Western Digital Corporation. Thanks a lot for your videos. Keep going🔥🔥

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว +11

      Woww great 🎉 Congratulations 💥 Would love to hear from you in LinkedIn. Please ping there.

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

      how did you apply for the company,it was on campus or off campus??

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

    this is gold, especially for the ones who have questions on when should we use DFS and when we should use BFS

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

    Hello sir, I got placed at LinkedIn, thank you for your videos and constant guidance!!!.

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

    Simply Makkhaan(Butter). What an amazing explanation....... Hat's Off.

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

    your explanations are so good that i just listen to them and go ahead and solve the problem

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

    Great explanation..Really enthralled by the way of explaining every bit

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

    Instead generating new string and find in in set we could compare two words
    def is_one_word_change(w1,w2):
    if len(w1)!=len(w2):
    return False
    wc = 0
    for i in range(len(w1)):
    if w1[i]!=w2[i]: wc+=1
    if wc>1: return False
    return wc==1
    this will reduce the time

  • @user-us7rg4cd6p
    @user-us7rg4cd6p 4 หลายเดือนก่อน

    legendary explanation! Good job buddy!

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

    Thank you uncle ☺️❣️

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

    Like before video as I know this will be awesome 😀 BFS approach I guess? Where at each step check new word can be formed with char. Replacement from A to Z...
    For better time complexity, put all words in set.

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

      Yep. You already solved it :D

    • @ayushthakur2896
      @ayushthakur2896 3 ปีที่แล้ว

      why using set gives better complexity?

    • @LGL1999
      @LGL1999 3 ปีที่แล้ว

      @@ayushthakur2896 Constant time access to elements in Sets vs Lists I think?

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

    you really draw out all the words such an eyesoar man

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

    basically, we're assuming all edges are weight 1 and doing a djikstra.

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

    Thanks you very much, I only needed the graph hint to solve this

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

    Very Nice Explanation! Thank you.

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

    Greatt explanation sir

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

    Hello Tech Dose,
    Amazing and detailed explanation.
    What will be the space complexity?

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

    Superb Thank you so much

  • @rajatgupta-ld1wg
    @rajatgupta-ld1wg 3 ปีที่แล้ว +4

    Just Curious, why you disliked this ques? at 0:08 :P btw I always find your videos easy to understand. Thanks :)

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

    You explained in an Excellent way

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

    Well explained, but if you use set(for find()) then I feel complexity will be O(N2.WLogW).

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

    Your explanation is to the point. Keep it up!

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

    this question was asked to me at amazon..

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

    amazing viedoe

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

    Awesome explanation, thanks you so much :)

  • @shivarammuthukumaraswamy7164
    @shivarammuthukumaraswamy7164 4 ปีที่แล้ว

    Thank you so very much.Best explanation for this problem.

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

    Fabulous! Very clear

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

    Pls, discuss the 2-way Bfs approach also for this qs.

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

    Thank you sir.very good explanation .please good the same one in graph too sir .it is very useful to know multiple approaches

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

    Nice

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

    Very well explained.

  • @user-sr1pk3yy8b
    @user-sr1pk3yy8b 3 ปีที่แล้ว +1

    Hi, thanks for the problem explanation. Question: why don't we put "wordList" to a Dictionary instead of Set so to make word comparison O(1)?

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

    Well explained, thanks

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

    I wish you are my csc sir

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

    I learn a lot from your videos.
    Can you guide us of how you manage to stay dedicated for coding while being working in corporate ? I am working in corporate, I too want to go too far in coding, but not able to due.
    Please guide us

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว

      Sure

    • @rohanseth1392
      @rohanseth1392 4 ปีที่แล้ว

      I liked your planning videos very much. Can you make a video telling us about the plan for those who are working in corporate

  • @alpishjain1317
    @alpishjain1317 3 ปีที่แล้ว

    excellent dry run!

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

    thank you so much..awesome..I am following your videos since 1 yr. I can't find your coding profiles anywhere.(want to see)😁

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

    Nice explanation 👍

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

    Thanks, it was amazing.

  • @HimanshuSingh-ob9qo
    @HimanshuSingh-ob9qo 4 ปีที่แล้ว +1

    Nice explanation

  • @BaljeetSingh-bx8yj
    @BaljeetSingh-bx8yj 4 ปีที่แล้ว +1

    Sirji pranaam 🙏🏻

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

    Why didn't you consider find and erase function time complexity in the Final Time complexity??
    Btw great explanation

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

      Maybe I missed 😅 It's easy to miss something when calculating time complexity.

  • @Mandeepsingh-jo5cf
    @Mandeepsingh-jo5cf 3 ปีที่แล้ว +1

    Thank you sir.

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

    Hey, well explained. Can you do it for word ladder 2 problem also ?

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

    U are great man

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

    Please make a video on the Manacher's Algorithm..

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว

      Sure bro. But Currently I am covering graph :)

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

    Great content 🔥🔥

  • @Dan-tg3gs
    @Dan-tg3gs 3 ปีที่แล้ว +1

    i was able to do this using BFS bidrectional

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

    Sir in graph we used visited matrix then why not here. The remove method here will charge O(n) thereby increasing the time complexity

  • @siddharthsinghvi9972
    @siddharthsinghvi9972 3 ปีที่แล้ว

    I think there will be an error we have to return 0 at the end as if the endword is also present but there is no path in the graph to end word so we will return 0 then

  • @raghugore3990
    @raghugore3990 4 ปีที่แล้ว

    Can u please provide solution and explanation for the below :
    Write a program to find Largest 4 digits Prime Number whose Sum of Digits is also Prime.
    1.Prime Number is any number that is divisible only by 1 and itself. Examples are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,........
    2.Sum of Digits means sum of all the digits in that number. Example is number is 1234 then the sum of digits is 1+2+3+4=10

  • @fadi.casual3796
    @fadi.casual3796 3 ปีที่แล้ว +1

    What tools do you use to draw on the screen? @TechDose?

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

    Can't we use dfs & dp to reduce complexity?

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

    could anybody please tell me that why DFS does not work in this problem? Need help thank you~

  • @pleasesirmorevideos4684
    @pleasesirmorevideos4684 4 ปีที่แล้ว

    so the main idea was to use O(n^2) to make the vali edges between words and then simply apply BFS?

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

    sir for checking string we are using set which gives us the result in average O(1) time then why have you written there that for string compare it is O(N*26*N) it should'nt be O(N*26) at 15:39?

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

      26 permutation for each letter. For a word, you will have 26*N. You can have N words at a level. So a total of (26*N*N).

    • @parteeksatija5536
      @parteeksatija5536 4 ปีที่แล้ว

      @@techdose4u Sir lets say there is a word "hit" now to try every combination time will be O(26*N) for one word and we can have total N words so time complexity would be O(26*N*N). Sir then What is W for in O(26*N*N*W)?

    • @paraschawla3757
      @paraschawla3757 3 ปีที่แล้ว

      @@parteeksatija5536
      * TC O(26*N*N*W)
      * N - Number of characters in String
      * 26*N - Number of transformations happening in a string of N characters
      * 26*N*N - Comparison with endWord string ( String comparison is O(N))
      * W - Number of Words in the BFS call
      Second multiplication by N is because all transformations i.e. 26*N occurrences of strings are being compared by endWord
      String comparison is O(N) , check stackoverflow.com/questions/55330338/time-complexity-of-string-comparison/55330371
      W - total number of words added in queue

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

    Hi, I just had a doubt regarding the following test case.
    beginWord = "a"
    endWord = "c"
    wordList = ["a","b","c"]
    can anyone clarify why its output is 2 and not 1?

    • @lokeshkoliparthi9268
      @lokeshkoliparthi9268 3 ปีที่แล้ว

      we have to start counting from first node

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

      First start "a" change to it a to z if it is present as a same then we ignored it( suppose after convert a to a then it is same then we ignore it then check for b to z and depth = 1) and check for other character and it is find then add it (convert a to c it is find then depth = 1+1) and returns it...

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

    *** JAVA VERSION OF YOUR ALGORITHM ***
    class Solution {
    public int ladderLength(String beginWord, String endWord, List wordList) {

    boolean isEndPresent=false;
    Set St=new HashSet();

    for(String s: wordList){

    if(s.equals(endWord)){
    isEndPresent=true;
    }

    St.add(s);
    }

    if(!isEndPresent) return 0;

    int depth=0;
    Queue Q=new LinkedList();
    Q.offer(beginWord);

    while(!Q.isEmpty()){

    depth+=1;
    int lSize=Q.size();

    while(lSize-->0){

    String curr=Q.poll();
    int len=curr.length();

    for(int i=0;i

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

    If we check popped string with the end word at the starting only not in the for loop then tym complexity will we O(n*26*w)? Am i right?

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

    I think you don't need to do line 14 to 21 in the latest version of the question

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว

      :o Dint check it

  • @F21SafiyyaIshaqSyed
    @F21SafiyyaIshaqSyed 11 วันที่ผ่านมา

    was asked in phone pe

  • @allen724
    @allen724 3 ปีที่แล้ว

    Can someone please explain why DFS doesnt work? I tried implementing with DFS and using a HashMap to store computed results already. But I am getting the wrong answer, getting 41/49 on leetcode.

  • @satyanarayanagokavarapu3011
    @satyanarayanagokavarapu3011 4 ปีที่แล้ว

    Design Search Autocomplete System can you make an video on this ?

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

    I have a doubt. in the given example how u transformed lot to dog as it is given that only one letter transformation is valid.

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

      That was incorrect. I had flagged the correction when I was showing the graph. Dint realize it earlier in the previous slide.

  • @yatinarora1252
    @yatinarora1252 3 ปีที่แล้ว

    I have tried this similar question from leetcode today...but the expected answer is 5 mine is 6.I was doing this some different algo..Bu I donot know that graph will be used in this question..Meaning this question is of graph

  • @TomJerry-bp9ig
    @TomJerry-bp9ig ปีที่แล้ว

  • @007-yashchoudhery4
    @007-yashchoudhery4 2 ปีที่แล้ว

    how you can make dog from lot? this connection is invalid.

  • @abhilashpatel3036
    @abhilashpatel3036 3 ปีที่แล้ว

    What's lsize doing? Please someone explain

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

    code link is broken, can you fix it.

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

    You mentioned curr.compare(temp) is taking O(N) time complexity, why not just check `if curr==temp` this would be O(1)

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

      curr==temp is not O(1). its o(len of the string). its does a deep check.

  • @kirtanprajapati8464
    @kirtanprajapati8464 3 ปีที่แล้ว

    hey bro apka brute force approch mind bloing he but kya iska optimal solution nhi he ?

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

    😀

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

    I looking for bidirectional bfs approach in the video :(

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว

      Don't worry. I will cover biderectional BFS in other questions. I thought it will be easier for most people to understand simple BFS. It will be helpful if you can recommend a most asked question in interview regarding birectional BFS :)

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

      @@techdose4u I think a simple question is :
      Given an undirected uniform graph, a source node and destination node, find minimum no of nodes exists in the path btw them.
      This is similar to word ladder 😅 I guess.

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว

      @@yeswanthbonagiri7142 Yea 😅 I needed a proper asked question.

    • @yeswanthbonagiri7142
      @yeswanthbonagiri7142 3 ปีที่แล้ว

      @@techdose4u leetcode.com/problems/open-the-lock/
      leetcode.com/problems/jump-game-iv/solution/

  • @HimanshuSingh-ob9qo
    @HimanshuSingh-ob9qo 4 ปีที่แล้ว +1

    👍

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

    What will be the complixity of this code?

  • @HimanshuSingh-ob9qo
    @HimanshuSingh-ob9qo 4 ปีที่แล้ว +1

    🙏

  • @HimanshuKumar-xz5tk
    @HimanshuKumar-xz5tk 3 ปีที่แล้ว

    What is the space complexity?

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

    are we using 0(zero) as true here?

  • @SHASHIKUMAR-pp4hg
    @SHASHIKUMAR-pp4hg 3 ปีที่แล้ว

    I tried using dfs+memorization but getting 44th testcase wrong anyone else

  • @21RandomMan
    @21RandomMan 2 ปีที่แล้ว

    uhh u can use bfs...

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

    Anyone noticed that TechDose has downvoted this question... 😂

  • @sakshisinha8164
    @sakshisinha8164 3 ปีที่แล้ว

    Why used set??????????

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

    Is this code is in java or c++ ?

  • @Sandeep-zd6dq
    @Sandeep-zd6dq 2 ปีที่แล้ว

    Leave everything else, At 0:17 you also disliked the problem 😂

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

    This is not the optimal way to solve this question. An nlogn solution exists

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

      could u please send that solution link?

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

    Github not found

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว

      It should work now. Try it.

  • @worldofafrontenddeveloper9187
    @worldofafrontenddeveloper9187 3 ปีที่แล้ว

    Thanks for the explanation.Just that too many ads , as I don't have premium.It is quite distracting.

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

    Dond dell me whad do do

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

    your code is not compact enough.

    • @jacobstech1777
      @jacobstech1777 3 ปีที่แล้ว

      # compact solution
      wordList = set(wordList)
      queue = collections.deque([[beginWord, 1]])
      while queue:
      word, length = queue.popleft()
      if word == endWord:
      return length
      for i in range(len(word)):
      for c in 'abcdefghijklmnopqrstuvwxyz':
      next_word = word[:i] + c + word[i+1:]
      if next_word in wordList:
      wordList.remove(next_word)
      queue.append([next_word, length + 1])
      return 0

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว

      👍🏼

  • @jatinvishwakarma5272
    @jatinvishwakarma5272 4 ปีที่แล้ว

    Why there is so dislike on the question, even you also disliked it?

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว

      Which question ?

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

    Great explanation..Really enthralled by the way of explaining every bit

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

    Great explanation..Really enthralled by the way of explaining every bit

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

    Great explanation..Really enthralled by the way of explaining every bit

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

    Great explanation..Really enthralled by the way of explaining every bit

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

    Great explanation..Really enthralled by the way of explaining every bit

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

    Great explanation..Really enthralled by the way of explaining every bit

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

    Great explanation..Really enthralled by the way of explaining every bit

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

    Great explanation..Really enthralled by the way of explaining every bit

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

    Great explanation..Really enthralled by the way of explaining every bit

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

    Great explanation..Really enthralled by the way of explaining every bit