1
00:00:00,800 --> 00:00:02,810
Hi, everyone, welcome to this new video.

2
00:00:02,840 --> 00:00:07,910
So in this video, we are going to write the code for finding out, first of all, on this question,

3
00:00:07,910 --> 00:00:12,010
Worldreader, for finding out the number of words that represent the new transmission sequence.

4
00:00:12,350 --> 00:00:12,740
Right.

5
00:00:13,310 --> 00:00:17,210
So, as discussed, what I need to do, we will copy code.

6
00:00:17,330 --> 00:00:19,120
So let's start copying the code.

7
00:00:19,760 --> 00:00:23,980
So, first of all, let's copy this one cell.

8
00:00:24,500 --> 00:00:24,930
Right.

9
00:00:25,370 --> 00:00:27,770
So here we will also have this cell.

10
00:00:28,200 --> 00:00:32,150
Uh, the naming cell is not very good.

11
00:00:33,920 --> 00:00:37,910
Naming cell is not very good, but yeah, it's fine.

12
00:00:38,720 --> 00:00:42,830
And what the cell will contain this time, it will contain word.

13
00:00:42,830 --> 00:00:44,600
It will contain one word.

14
00:00:45,500 --> 00:00:45,930
Right.

15
00:00:46,250 --> 00:00:54,050
So what I want to say here is so I will have nodes like this, I will have this word.

16
00:00:54,260 --> 00:00:55,790
I will have nodes like this here.

17
00:00:56,150 --> 00:01:03,470
And the distances run by the distance is one because in the valley returning the answer, I need to

18
00:01:03,470 --> 00:01:04,900
also include the big word.

19
00:01:05,360 --> 00:01:08,270
So that's I am initializing it to one and not zero.

20
00:01:08,840 --> 00:01:15,410
So now the second I will be basically hard and two.

21
00:01:16,040 --> 00:01:20,660
So I'm saying this is one cell instead of saying cell, let's name it to node.

22
00:01:21,140 --> 00:01:22,580
Nor will be a better option here.

23
00:01:22,580 --> 00:01:22,940
Right.

24
00:01:23,330 --> 00:01:25,650
Node seems a lot better here.

25
00:01:25,820 --> 00:01:31,680
So instead of cell, let's name it Node eight.

26
00:01:31,820 --> 00:01:32,290
Fine.

27
00:01:32,300 --> 00:01:34,250
Now let's copy the rest of the code.

28
00:01:35,880 --> 00:01:38,190
OK, so let's compare this.

29
00:01:45,350 --> 00:01:50,870
All right, so first of all, there is nothing called the grid, so let's remove this line and we do

30
00:01:50,870 --> 00:01:51,770
not have that.

31
00:01:52,850 --> 00:01:54,500
I can move in either direction.

32
00:01:54,530 --> 00:02:02,090
That's wrong, because for replacing one character, I have 26 option May six alphabets are there.

33
00:02:02,600 --> 00:02:03,530
So remove that.

34
00:02:04,910 --> 00:02:09,289
There is nothing called grid here we need one with.

35
00:02:09,919 --> 00:02:10,880
That's true.

36
00:02:11,300 --> 00:02:16,310
But in this case, what do we need for me if I need this already?

37
00:02:16,310 --> 00:02:25,970
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

38
00:02:25,970 --> 00:02:29,720
create the list of words that I have already visited.

39
00:02:29,750 --> 00:02:30,200
Right.

40
00:02:30,800 --> 00:02:32,180
So let's do that.

41
00:02:33,770 --> 00:02:38,080
What do we need here is we can create a map or set.

42
00:02:38,840 --> 00:02:50,110
So let's say I am using that set of words so it will be of string and visited.

43
00:02:51,440 --> 00:02:51,890
Right.

44
00:02:51,920 --> 00:02:59,120
So I have this visitor said it will contain the list of words that I already visited then.

45
00:02:59,130 --> 00:03:00,500
Q of A..

46
00:03:02,780 --> 00:03:11,570
And I need to insert the biggest word, so I need to insert bigger word and the value will be one and

47
00:03:11,570 --> 00:03:15,860
not zero, because in the output, we also need to include the bigger word.

48
00:03:16,130 --> 00:03:18,730
So that's why I need to initialize it with one.

49
00:03:18,740 --> 00:03:20,120
So I'm realizing it with one.

50
00:03:20,480 --> 00:03:22,290
And this word has been visited.

51
00:03:22,670 --> 00:03:26,990
So what I will do, I will mark that this word has been monitored.

52
00:03:26,990 --> 00:03:30,350
So was they third said, I will insert this word.

53
00:03:30,890 --> 00:03:35,870
So visited said dot insert begin word.

54
00:03:37,450 --> 00:03:47,420
Right, that's said, while it is not empty, nobody could not find culotte pop and hear what they need

55
00:03:47,420 --> 00:03:47,920
to check.

56
00:03:47,960 --> 00:03:51,520
I need to check whether I have reached the last word or not.

57
00:03:51,800 --> 00:03:56,240
So if they did, what word is it close to the end word?

58
00:03:56,720 --> 00:04:00,890
If I'm able to reach the last word, I will return the distance.

59
00:04:00,890 --> 00:04:01,280
Right.

60
00:04:02,070 --> 00:04:04,910
Otherwise, I was moving in either directions.

61
00:04:05,270 --> 00:04:10,520
But here, as I told you, I have this word here, right.

62
00:04:10,910 --> 00:04:13,790
So what I will do, I will iterate over this word.

63
00:04:15,020 --> 00:04:16,430
I will try or this word.

64
00:04:16,430 --> 00:04:22,670
And for each character, there are 25 replacement rate.

65
00:04:22,850 --> 00:04:26,630
So I will try to replace it with 25 other characters.

66
00:04:26,930 --> 00:04:32,430
And I will see that whether the new word is present in the word list or not.

67
00:04:32,450 --> 00:04:34,730
Wait, so.

68
00:04:39,590 --> 00:04:41,210
Let's change.

69
00:04:44,400 --> 00:04:48,030
OK, so actually, this entire court will change.

70
00:04:48,060 --> 00:04:51,520
So let's take the help of this court for writing the new code.

71
00:04:51,900 --> 00:04:53,550
So what I need to do, I will.

72
00:04:53,550 --> 00:04:55,160
I read over the word right.

73
00:04:55,170 --> 00:04:56,610
So I equals zero.

74
00:04:57,030 --> 00:05:02,850
I elastin t dot word, dot says, and C++.

75
00:05:02,970 --> 00:05:11,670
And for each character, for each character, I have 25 replacement rate.

76
00:05:11,910 --> 00:05:17,310
So Jacob's zero G less than 26 G plus plus.

77
00:05:18,090 --> 00:05:19,910
Let's try to find out the new word.

78
00:05:20,340 --> 00:05:21,590
So whatever the new word.

79
00:05:22,080 --> 00:05:24,270
So the new word.

80
00:05:27,400 --> 00:05:30,030
New word will be the original word.

81
00:05:30,360 --> 00:05:35,000
And we need to change the Ayyad character of the new word.

82
00:05:35,310 --> 00:05:38,840
So I character of the word can be changed to.

83
00:05:40,790 --> 00:05:48,560
It can be changed like this late, so this is the new world, what I'm doing here.

84
00:05:50,270 --> 00:05:54,140
See, let's talk about this word here only.

85
00:05:54,590 --> 00:05:55,790
So I have this word.

86
00:05:55,850 --> 00:05:59,000
Hate what I'm doing.

87
00:05:59,000 --> 00:06:00,680
I am maltreating over the word here.

88
00:06:01,580 --> 00:06:01,970
Right.

89
00:06:02,180 --> 00:06:04,010
And for each character.

90
00:06:04,910 --> 00:06:08,000
For each character, I am I reading.

91
00:06:09,080 --> 00:06:12,930
Sorry, this will be g g equals zero g less than 60 plus.

92
00:06:12,930 --> 00:06:15,200
Plus I am trying to create a new word.

93
00:06:15,660 --> 00:06:18,080
So how the new word will be created for example.

94
00:06:18,230 --> 00:06:19,600
I will remain same.

95
00:06:19,610 --> 00:06:23,540
I, I'm going to replace each with all the possibilities.

96
00:06:23,840 --> 00:06:24,220
Right.

97
00:06:24,410 --> 00:06:25,630
So all the possibilities.

98
00:06:25,640 --> 00:06:27,710
That is how, that's how you can replace it.

99
00:06:28,370 --> 00:06:32,450
So I will try to replace it with A then B then C Thandi and so on.

100
00:06:32,960 --> 00:06:40,130
So for example, if I replacing it with C then it will become the new word will become c.i.t. and this

101
00:06:40,310 --> 00:06:43,160
C it must be present in the word list.

102
00:06:43,880 --> 00:06:44,330
Right.

103
00:06:45,740 --> 00:07:01,400
So if the new world, if the new world is present in if the new world is present in the wordlist and

104
00:07:02,060 --> 00:07:10,190
this new world has not been visited late, you remember what is the condition here if it has not been

105
00:07:10,190 --> 00:07:10,700
visited?

106
00:07:11,120 --> 00:07:18,440
So if the new world has not been visited, so we have visited said so instead we have function.

107
00:07:20,650 --> 00:07:33,370
Fine, so let's try to find this new word instead, and I am not able to find this word that means this

108
00:07:33,370 --> 00:07:34,900
word is coming for the first time.

109
00:07:35,240 --> 00:07:40,960
If this word is coming for the first time, then it must be part of our cue.

110
00:07:42,200 --> 00:07:42,670
Right.

111
00:07:43,000 --> 00:07:49,480
And when you are inserting it in Q you will do dist. plus one.

112
00:07:49,900 --> 00:07:50,320
Right.

113
00:07:50,530 --> 00:07:52,540
And after you have inserted in.

114
00:07:52,540 --> 00:08:01,120
Q You need to mark that this word has been visited, so you need to mark that this word has been visited.

115
00:08:01,120 --> 00:08:09,930
So visited is I said so said don't insert new word right now.

116
00:08:10,330 --> 00:08:17,170
One thing that we need to do here is so I need to check whether the new word is present in wordlist

117
00:08:17,170 --> 00:08:17,590
or not.

118
00:08:17,800 --> 00:08:19,740
So this is my wordlist, right.

119
00:08:20,170 --> 00:08:23,190
I want to check whether the word is present or not.

120
00:08:23,350 --> 00:08:28,020
So I need to iterate over the complete list to figure out if it is not present.

121
00:08:28,360 --> 00:08:30,230
So that is taking time.

122
00:08:30,250 --> 00:08:31,730
That is not sufficient.

123
00:08:31,960 --> 00:08:36,210
So what we can do, we can convert this list with the help of this list.

124
00:08:36,220 --> 00:08:44,590
We can make a map of words and we can check whether the word is present or not, either map or set,

125
00:08:44,950 --> 00:08:48,370
so we can create a state out of it or a map out of it.

126
00:08:48,670 --> 00:08:51,880
And then we can check in constant time by the R word.

127
00:08:51,880 --> 00:08:54,930
As President said, our map or it is not present.

128
00:08:54,960 --> 00:08:55,220
Right.

129
00:08:55,330 --> 00:08:57,130
So let's build a set of words.

130
00:08:57,670 --> 00:08:59,020
Let's build another set.

131
00:08:59,030 --> 00:09:01,960
Write another set.

132
00:09:04,480 --> 00:09:16,270
Strings and what should be the name name should be allowed words or valid words, valid word.

133
00:09:18,290 --> 00:09:19,770
Valid of our list, right?

134
00:09:20,540 --> 00:09:26,740
Yeah, it seems fine, so what we can do, we need to insert all the words so I can I trade.

135
00:09:27,560 --> 00:09:29,900
So I called zero elastin.

136
00:09:31,670 --> 00:09:36,980
Wordlist says I placeless.

137
00:09:37,670 --> 00:09:41,390
So we need to insert all the words insert.

138
00:09:44,880 --> 00:09:52,500
Wait, I need to insert all the word insert.

139
00:09:58,730 --> 00:10:04,220
Right, so now our searching, so this cold is not useful, so let's be clear this.

140
00:10:07,890 --> 00:10:12,060
Now I know what I need to do, I need to check whether the new word is present in the

141
00:10:14,790 --> 00:10:16,270
allowed words or not.

142
00:10:17,100 --> 00:10:18,390
So how can I check?

143
00:10:18,540 --> 00:10:19,290
Very simple.

144
00:10:19,800 --> 00:10:28,520
So Valeyard word list dot find a new word.

145
00:10:29,940 --> 00:10:40,170
So if this new word is present in the value the word list, then it's called.

146
00:10:45,810 --> 00:10:50,280
All right, so what I'm doing here is.

147
00:10:53,550 --> 00:10:58,980
So I created this set so that I can search in Question Time, then I am migrating over this list of

148
00:10:58,980 --> 00:11:02,210
words and I'm sorting all the words in the set.

149
00:11:03,060 --> 00:11:03,420
Right.

150
00:11:03,600 --> 00:11:09,060
So that I can check here whether the new word is present is a valid word or not.

151
00:11:09,390 --> 00:11:15,060
So if the given word is a valid word, if the new word is a valid word and we are visiting the new word

152
00:11:15,060 --> 00:11:17,220
for the first time, then you will inserting.

153
00:11:17,220 --> 00:11:21,660
Q and you will insert the new word in the visitor at a later date.

154
00:11:21,690 --> 00:11:24,010
So that is what we wanted to do.

155
00:11:24,780 --> 00:11:31,680
And finally, I will return the distance and if I'm not able to reach the last word, then I will have

156
00:11:31,680 --> 00:11:32,220
10 minutes.

157
00:11:32,220 --> 00:11:34,020
And no, I do not need to return my lesson.

158
00:11:34,020 --> 00:11:35,970
I need to return zero according to the question.

159
00:11:35,970 --> 00:11:36,300
Right.

160
00:11:36,780 --> 00:11:37,980
I need to return zero.

161
00:11:40,410 --> 00:11:41,960
So I will return zero.

162
00:11:44,880 --> 00:11:46,920
So that will be the complete code.

163
00:11:47,250 --> 00:11:47,640
Right.

164
00:11:47,970 --> 00:11:55,320
So one shortcut is instead of iterating and inserting the words like this, there is another way of

165
00:11:55,320 --> 00:12:00,180
inserting all the words at once, and that is the syntax.

166
00:12:02,500 --> 00:12:03,190
This is.

167
00:12:04,450 --> 00:12:17,260
Wordlist darte, Biggin and Wordlist darte, and so this is the Syntex.

168
00:12:18,470 --> 00:12:25,430
Right, so initialise Lavallade wordlist with the wordlist, so that is the shortcut,

169
00:12:28,850 --> 00:12:29,090
right?

170
00:12:30,470 --> 00:12:32,450
So now I think our court will work.

171
00:12:33,710 --> 00:12:35,900
Let's try to learn our code and then will submit.

172
00:12:37,760 --> 00:12:38,890
Oh sorry.

173
00:12:40,490 --> 00:12:43,580
And it should be comma and it will be G.

174
00:12:48,490 --> 00:12:52,960
Sorry again, GWM 26.

175
00:12:55,030 --> 00:12:56,280
What's happening here?

176
00:13:08,700 --> 00:13:09,870
Yep, it's correct now.

177
00:13:11,810 --> 00:13:13,550
It will be actually Dartford.

178
00:13:22,420 --> 00:13:25,710
OK, so actually, we need to call the function find here,

179
00:13:31,600 --> 00:13:37,590
I don't know what's happening here, why the characters are getting deleted.

180
00:13:45,070 --> 00:13:46,230
Let me read it again.

181
00:13:46,930 --> 00:13:56,110
So we need to check whether the given word is visited or not so visitors don't find a new word.

182
00:13:58,480 --> 00:13:59,920
This word is not visited.

183
00:14:10,280 --> 00:14:15,590
Yep, so our goal is working after so much of hard work, let's try to meet our goal.

184
00:14:17,000 --> 00:14:17,410
Yep.

185
00:14:17,420 --> 00:14:23,030
So basically our goal is working and let us go through the entire goal one more time.

186
00:14:23,360 --> 00:14:25,430
So, again, what I'm doing, I am creating node.

187
00:14:25,430 --> 00:14:27,500
This node will contain the word and the distance.

188
00:14:27,800 --> 00:14:33,970
So it will contain the word heard and the distance, which is one by one, because according to that

189
00:14:34,250 --> 00:14:36,650
statement, we also need to count this one also.

190
00:14:36,710 --> 00:14:42,140
Then we need to create this set so that we can improve our searching error rate.

191
00:14:43,010 --> 00:14:45,110
So we are creating the site.

192
00:14:45,590 --> 00:14:48,640
We also need one with very obviously creating you.

193
00:14:48,650 --> 00:14:53,030
I'm inserting the word and I'm marking that we convert has been inserted.

194
00:14:53,300 --> 00:14:58,940
So while it is not pick a different element, remove the element from the top, if the given what is

195
00:14:58,940 --> 00:15:02,000
equal to and what you can return the distance.

196
00:15:02,000 --> 00:15:08,150
Otherwise you need to iterate over the world, otherwise you need to iterate over the word.

197
00:15:08,690 --> 00:15:13,270
And for each character there are 25 replacement.

198
00:15:13,280 --> 00:15:16,280
So each character there are replacements.

199
00:15:16,910 --> 00:15:18,980
So we'll try to replace every character.

200
00:15:19,280 --> 00:15:20,960
You will get a few nodes.

201
00:15:21,230 --> 00:15:27,390
And if the new word is a valid word, so what is a valid word that it must represent in the word list?

202
00:15:27,710 --> 00:15:35,420
So if it is a valid word, right, and this word has not been visited, then insert the word in the

203
00:15:35,420 --> 00:15:37,840
queue and visit this word right.

204
00:15:37,850 --> 00:15:40,260
That standard BFC algorithm.

205
00:15:40,280 --> 00:15:45,520
And finally, if you are not able to reach the end word, we will return zero.

206
00:15:46,250 --> 00:15:48,320
So that's how the code is working.

207
00:15:49,460 --> 00:15:51,110
So this is all about this problem.

208
00:15:51,250 --> 00:15:55,010
Guys, this problem is a little bit difficult, but we can solve this, right?

209
00:15:55,020 --> 00:15:56,490
We can solve hard problems also.

210
00:15:56,960 --> 00:15:59,150
So this is all about this device.

211
00:15:59,150 --> 00:16:00,470
I will see you in the next one.

212
00:16:00,500 --> 00:16:01,070
Thank you.

