Hi, everyone, welcome to this new video.
So in this video, we are going to write the code for finding out, first of all, on this question,
Worldreader, for finding out the number of words that represent the new transmission sequence.
Right.
So, as discussed, what I need to do, we will copy code.
So let's start copying the code.
So, first of all, let's copy this one cell.
Right.
So here we will also have this cell.
Uh, the naming cell is not very good.
Naming cell is not very good, but yeah, it's fine.
And what the cell will contain this time, it will contain word.
It will contain one word.
Right.
So what I want to say here is so I will have nodes like this, I will have this word.
I will have nodes like this here.
And the distances run by the distance is one because in the valley returning the answer, I need to
also include the big word.
So that's I am initializing it to one and not zero.
So now the second I will be basically hard and two.
So I'm saying this is one cell instead of saying cell, let's name it to node.
Nor will be a better option here.
Right.
Node seems a lot better here.
So instead of cell, let's name it Node eight.
Fine.
Now let's copy the rest of the code.
OK, so let's compare this.
All right, so first of all, there is nothing called the grid, so let's remove this line and we do
not have that.
I can move in either direction.
That's wrong, because for replacing one character, I have 26 option May six alphabets are there.
So remove that.
There is nothing called grid here we need one with.
That's true.
But in this case, what do we need for me if I need this already?
But I will do, I will create a map map or I said I will create a visited off map or so this map will
create the list of words that I have already visited.
Right.
So let's do that.
What do we need here is we can create a map or set.
So let's say I am using that set of words so it will be of string and visited.
Right.
So I have this visitor said it will contain the list of words that I already visited then.
Q of A..
And I need to insert the biggest word, so I need to insert bigger word and the value will be one and
not zero, because in the output, we also need to include the bigger word.
So that's why I need to initialize it with one.
So I'm realizing it with one.
And this word has been visited.
So what I will do, I will mark that this word has been monitored.
So was they third said, I will insert this word.
So visited said dot insert begin word.
Right, that's said, while it is not empty, nobody could not find culotte pop and hear what they need
to check.
I need to check whether I have reached the last word or not.
So if they did, what word is it close to the end word?
If I'm able to reach the last word, I will return the distance.
Right.
Otherwise, I was moving in either directions.
But here, as I told you, I have this word here, right.
So what I will do, I will iterate over this word.
I will try or this word.
And for each character, there are 25 replacement rate.
So I will try to replace it with 25 other characters.
And I will see that whether the new word is present in the word list or not.
Wait, so.
Let's change.
OK, so actually, this entire court will change.
So let's take the help of this court for writing the new code.
So what I need to do, I will.
I read over the word right.
So I equals zero.
I elastin t dot word, dot says, and C++.
And for each character, for each character, I have 25 replacement rate.
So Jacob's zero G less than 26 G plus plus.
Let's try to find out the new word.
So whatever the new word.
So the new word.
New word will be the original word.
And we need to change the Ayyad character of the new word.
So I character of the word can be changed to.
It can be changed like this late, so this is the new world, what I'm doing here.
See, let's talk about this word here only.
So I have this word.
Hate what I'm doing.
I am maltreating over the word here.
Right.
And for each character.
For each character, I am I reading.
Sorry, this will be g g equals zero g less than 60 plus.
Plus I am trying to create a new word.
So how the new word will be created for example.
I will remain same.
I, I'm going to replace each with all the possibilities.
Right.
So all the possibilities.
That is how, that's how you can replace it.
So I will try to replace it with A then B then C Thandi and so on.
So for example, if I replacing it with C then it will become the new word will become c.i.t. and this
C it must be present in the word list.
Right.
So if the new world, if the new world is present in if the new world is present in the wordlist and
this new world has not been visited late, you remember what is the condition here if it has not been
visited?
So if the new world has not been visited, so we have visited said so instead we have function.
Fine, so let's try to find this new word instead, and I am not able to find this word that means this
word is coming for the first time.
If this word is coming for the first time, then it must be part of our cue.
Right.
And when you are inserting it in Q you will do dist. plus one.
Right.
And after you have inserted in.
Q You need to mark that this word has been visited, so you need to mark that this word has been visited.
So visited is I said so said don't insert new word right now.
One thing that we need to do here is so I need to check whether the new word is present in wordlist
or not.
So this is my wordlist, right.
I want to check whether the word is present or not.
So I need to iterate over the complete list to figure out if it is not present.
So that is taking time.
That is not sufficient.
So what we can do, we can convert this list with the help of this list.
We can make a map of words and we can check whether the word is present or not, either map or set,
so we can create a state out of it or a map out of it.
And then we can check in constant time by the R word.
As President said, our map or it is not present.
Right.
So let's build a set of words.
Let's build another set.
Write another set.
Strings and what should be the name name should be allowed words or valid words, valid word.
Valid of our list, right?
Yeah, it seems fine, so what we can do, we need to insert all the words so I can I trade.
So I called zero elastin.
Wordlist says I placeless.
So we need to insert all the words insert.
Wait, I need to insert all the word insert.
Right, so now our searching, so this cold is not useful, so let's be clear this.
Now I know what I need to do, I need to check whether the new word is present in the
allowed words or not.
So how can I check?
Very simple.
So Valeyard word list dot find a new word.
So if this new word is present in the value the word list, then it's called.
All right, so what I'm doing here is.
So I created this set so that I can search in Question Time, then I am migrating over this list of
words and I'm sorting all the words in the set.
Right.
So that I can check here whether the new word is present is a valid word or not.
So if the given word is a valid word, if the new word is a valid word and we are visiting the new word
for the first time, then you will inserting.
Q and you will insert the new word in the visitor at a later date.
So that is what we wanted to do.
And finally, I will return the distance and if I'm not able to reach the last word, then I will have
10 minutes.
And no, I do not need to return my lesson.
I need to return zero according to the question.
Right.
I need to return zero.
So I will return zero.
So that will be the complete code.
Right.
So one shortcut is instead of iterating and inserting the words like this, there is another way of
inserting all the words at once, and that is the syntax.
This is.
Wordlist darte, Biggin and Wordlist darte, and so this is the Syntex.
Right, so initialise Lavallade wordlist with the wordlist, so that is the shortcut,
right?
So now I think our court will work.
Let's try to learn our code and then will submit.
Oh sorry.
And it should be comma and it will be G.
Sorry again, GWM 26.
What's happening here?
Yep, it's correct now.
It will be actually Dartford.
OK, so actually, we need to call the function find here,
I don't know what's happening here, why the characters are getting deleted.
Let me read it again.
So we need to check whether the given word is visited or not so visitors don't find a new word.
This word is not visited.
Yep, so our goal is working after so much of hard work, let's try to meet our goal.
Yep.
So basically our goal is working and let us go through the entire goal one more time.
So, again, what I'm doing, I am creating node.
This node will contain the word and the distance.
So it will contain the word heard and the distance, which is one by one, because according to that
statement, we also need to count this one also.
Then we need to create this set so that we can improve our searching error rate.
So we are creating the site.
We also need one with very obviously creating you.
I'm inserting the word and I'm marking that we convert has been inserted.
So while it is not pick a different element, remove the element from the top, if the given what is
equal to and what you can return the distance.
Otherwise you need to iterate over the world, otherwise you need to iterate over the word.
And for each character there are 25 replacement.
So each character there are replacements.
So we'll try to replace every character.
You will get a few nodes.
And if the new word is a valid word, so what is a valid word that it must represent in the word list?
So if it is a valid word, right, and this word has not been visited, then insert the word in the
queue and visit this word right.
That standard BFC algorithm.
And finally, if you are not able to reach the end word, we will return zero.
So that's how the code is working.
So this is all about this problem.
Guys, this problem is a little bit difficult, but we can solve this, right?
We can solve hard problems also.
So this is all about this device.
I will see you in the next one.
Thank you.