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".
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
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.
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
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
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
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 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)?
@@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
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?
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...
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.
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
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 :)
@@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.
# 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
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".
Yea. I did that in graph and I have flagged a correction there.
@@techdose4u Cool.. keep it up!!
@@chiragmali6752 thanks :)
Hey Man, I got placed today at Western Digital Corporation. Thanks a lot for your videos. Keep going🔥🔥
Woww great 🎉 Congratulations 💥 Would love to hear from you in LinkedIn. Please ping there.
how did you apply for the company,it was on campus or off campus??
this is gold, especially for the ones who have questions on when should we use DFS and when we should use BFS
Hello sir, I got placed at LinkedIn, thank you for your videos and constant guidance!!!.
Great ❤️
Simply Makkhaan(Butter). What an amazing explanation....... Hat's Off.
Thanks :)
your explanations are so good that i just listen to them and go ahead and solve the problem
Nice :)
Great explanation..Really enthralled by the way of explaining every bit
Thanks
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
👍
legendary explanation! Good job buddy!
Thank you uncle ☺️❣️
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.
Yep. You already solved it :D
why using set gives better complexity?
@@ayushthakur2896 Constant time access to elements in Sets vs Lists I think?
you really draw out all the words such an eyesoar man
😅
basically, we're assuming all edges are weight 1 and doing a djikstra.
in simple words BFS
Thanks you very much, I only needed the graph hint to solve this
Nice :)
Very Nice Explanation! Thank you.
Welcome 🤗
Greatt explanation sir
Hello Tech Dose,
Amazing and detailed explanation.
What will be the space complexity?
Superb Thank you so much
Just Curious, why you disliked this ques? at 0:08 :P btw I always find your videos easy to understand. Thanks :)
😅
You explained in an Excellent way
Thanks
Well explained, but if you use set(for find()) then I feel complexity will be O(N2.WLogW).
Your explanation is to the point. Keep it up!
Thanks
this question was asked to me at amazon..
Nice :)
amazing viedoe
Thanks
Awesome explanation, thanks you so much :)
Welcome :)
Thank you so very much.Best explanation for this problem.
Fabulous! Very clear
Thanks 😊
Pls, discuss the 2-way Bfs approach also for this qs.
Sure I will try
Thank you sir.very good explanation .please good the same one in graph too sir .it is very useful to know multiple approaches
Welcome :)
Nice
Thanks
Very well explained.
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)?
Well explained, thanks
I wish you are my csc sir
🤗
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
Sure
I liked your planning videos very much. Can you make a video telling us about the plan for those who are working in corporate
excellent dry run!
thank you so much..awesome..I am following your videos since 1 yr. I can't find your coding profiles anywhere.(want to see)😁
Thanks :)
Nice explanation 👍
Thanks
Thanks, it was amazing.
Welcome :)
Nice explanation
Thanks
Sirji pranaam 🙏🏻
🙏
Why didn't you consider find and erase function time complexity in the Final Time complexity??
Btw great explanation
Maybe I missed 😅 It's easy to miss something when calculating time complexity.
Thank you sir.
Welcome :)
Hey, well explained. Can you do it for word ladder 2 problem also ?
Already done.
U are great man
Thanks
Please make a video on the Manacher's Algorithm..
Sure bro. But Currently I am covering graph :)
Great content 🔥🔥
Thanks
i was able to do this using BFS bidrectional
Great ❤️
Sir in graph we used visited matrix then why not here. The remove method here will charge O(n) thereby increasing the time complexity
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
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
What tools do you use to draw on the screen? @TechDose?
Can't we use dfs & dp to reduce complexity?
could anybody please tell me that why DFS does not work in this problem? Need help thank you~
so the main idea was to use O(n^2) to make the vali edges between words and then simply apply BFS?
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?
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).
@@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)?
@@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
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?
we have to start counting from first node
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...
*** 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
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?
I think you don't need to do line 14 to 21 in the latest version of the question
:o Dint check it
was asked in phone pe
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.
Design Search Autocomplete System can you make an video on this ?
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.
That was incorrect. I had flagged the correction when I was showing the graph. Dint realize it earlier in the previous slide.
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
👍
❤
how you can make dog from lot? this connection is invalid.
What's lsize doing? Please someone explain
code link is broken, can you fix it.
I will check
You mentioned curr.compare(temp) is taking O(N) time complexity, why not just check `if curr==temp` this would be O(1)
curr==temp is not O(1). its o(len of the string). its does a deep check.
hey bro apka brute force approch mind bloing he but kya iska optimal solution nhi he ?
😀
😁
I looking for bidirectional bfs approach in the video :(
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 :)
@@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.
@@yeswanthbonagiri7142 Yea 😅 I needed a proper asked question.
@@techdose4u leetcode.com/problems/open-the-lock/
leetcode.com/problems/jump-game-iv/solution/
👍
👍
What will be the complixity of this code?
🙏
🙏
What is the space complexity?
are we using 0(zero) as true here?
I tried using dfs+memorization but getting 44th testcase wrong anyone else
uhh u can use bfs...
Anyone noticed that TechDose has downvoted this question... 😂
Why used set??????????
Is this code is in java or c++ ?
Cpp
Leave everything else, At 0:17 you also disliked the problem 😂
This is not the optimal way to solve this question. An nlogn solution exists
could u please send that solution link?
Github not found
It should work now. Try it.
Thanks for the explanation.Just that too many ads , as I don't have premium.It is quite distracting.
Dond dell me whad do do
your code is not compact enough.
# 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
👍🏼
Why there is so dislike on the question, even you also disliked it?
Which question ?
Great explanation..Really enthralled by the way of explaining every bit
Great explanation..Really enthralled by the way of explaining every bit
Thanks 😊
Great explanation..Really enthralled by the way of explaining every bit
Great explanation..Really enthralled by the way of explaining every bit
Great explanation..Really enthralled by the way of explaining every bit
Great explanation..Really enthralled by the way of explaining every bit
Great explanation..Really enthralled by the way of explaining every bit
Great explanation..Really enthralled by the way of explaining every bit
Great explanation..Really enthralled by the way of explaining every bit
Great explanation..Really enthralled by the way of explaining every bit