1
00:00:01,080 --> 00:00:03,000
Hi, everyone, welcome to this new video.

2
00:00:03,030 --> 00:00:08,370
So in this video, what we are going to do, we are going to write the code for the rotten oranges and

3
00:00:08,370 --> 00:00:14,130
we discussed that we can use the algorithm to find out the minimum number of minutes because if it gives

4
00:00:14,130 --> 00:00:15,240
you the shortest path.

5
00:00:15,570 --> 00:00:18,000
Right, so we can copy the code.

6
00:00:18,000 --> 00:00:23,750
We have written before a code a lot of times, so we can copy the code from here.

7
00:00:24,060 --> 00:00:25,230
So let's copy this.

8
00:00:27,000 --> 00:00:28,230
Let's start here.

9
00:00:30,920 --> 00:00:36,280
Right, so I need X, Y and time instead of distance, let's call it time.

10
00:00:36,310 --> 00:00:37,900
Time is more stable here, right?

11
00:00:38,960 --> 00:00:41,240
Now, let's compare this part.

12
00:00:45,840 --> 00:00:47,080
Let's start here.

13
00:00:48,390 --> 00:00:53,400
So let's talk about the first line so we do not need the first line here in this public statement.

14
00:00:53,400 --> 00:00:54,370
So let's remove this.

15
00:00:55,200 --> 00:00:58,770
Now I can move on for direction, right?

16
00:00:58,770 --> 00:01:01,100
I can move in for direction and not wait.

17
00:01:01,530 --> 00:01:05,019
So let's change it to four to four.

18
00:01:05,850 --> 00:01:07,230
I cannot move diagonally.

19
00:01:07,230 --> 00:01:11,850
So remove all the diagonal change in X and Y coordinate.

20
00:01:12,150 --> 00:01:15,540
So I need to remove this also.

21
00:01:16,500 --> 00:01:22,500
Similarly, remove this and what else.

22
00:01:22,530 --> 00:01:24,450
So this will get removed.

23
00:01:26,190 --> 00:01:27,360
This will get removed.

24
00:01:28,230 --> 00:01:29,400
This will get removed.

25
00:01:29,410 --> 00:01:30,630
And this.

26
00:01:31,390 --> 00:01:31,740
Right.

27
00:01:31,890 --> 00:01:37,170
So these are total four directions in which I can move.

28
00:01:40,990 --> 00:01:49,210
Yep, now this is Ambrose Animatrix and Gross and great, so this will be M, which is great Nazis and

29
00:01:49,210 --> 00:01:53,510
for finding out the value of and it will be good enough.

30
00:01:53,740 --> 00:01:55,740
Zero Nazis.

31
00:01:57,460 --> 00:01:57,960
Fine.

32
00:01:58,450 --> 00:01:59,950
We need to create one visitor today.

33
00:02:00,670 --> 00:02:02,710
Ambrose and and columns.

34
00:02:02,710 --> 00:02:07,920
Initialise with false Guiyu of cell and no.

35
00:02:08,169 --> 00:02:09,639
So what is the source of our text.

36
00:02:09,669 --> 00:02:11,140
So what will be the source of our text.

37
00:02:11,590 --> 00:02:18,110
I think what we need to do here is we need to push, we need to push all oranges.

38
00:02:18,940 --> 00:02:19,220
Right.

39
00:02:19,360 --> 00:02:21,720
We need to push Alderton oranges in the queue.

40
00:02:21,970 --> 00:02:27,100
So if this is your matrix and these are revalues, let's say this is true.

41
00:02:27,100 --> 00:02:27,910
This is true.

42
00:02:28,270 --> 00:02:31,930
And this is to Andrest, all the values are zeros and ones.

43
00:02:31,930 --> 00:02:34,000
So we are not interested in zeros.

44
00:02:34,570 --> 00:02:35,970
So let's write ones.

45
00:02:36,830 --> 00:02:41,800
This is one one one, one letter, one one here, one here, one here, one here.

46
00:02:41,800 --> 00:02:42,190
And list.

47
00:02:42,200 --> 00:02:44,050
All values are zero rate.

48
00:02:44,350 --> 00:02:49,900
So we need to do we need to push all the indexes that are containing two.

49
00:02:49,900 --> 00:02:51,100
So we need to push this.

50
00:02:51,100 --> 00:02:52,240
We need to push this.

51
00:02:52,600 --> 00:02:54,220
We need to push this right.

52
00:02:54,220 --> 00:02:55,650
We need to push all of them.

53
00:02:56,110 --> 00:03:00,780
So since we need to push all of them.

54
00:03:00,790 --> 00:03:05,230
So what do we need to get rid of the great rate we need to iterate.

55
00:03:06,190 --> 00:03:08,430
So let's add rate over the grid.

56
00:03:08,440 --> 00:03:12,460
So I call zero, I list an M I C++.

57
00:03:12,880 --> 00:03:14,320
Let me remove this.

58
00:03:17,400 --> 00:03:31,760
Uh, yep, so we need to hydrate, so J equals zero G less than n g plus plus to F this is a rotten

59
00:03:31,760 --> 00:03:32,210
orange.

60
00:03:33,080 --> 00:03:38,280
So F greater Fiji is equals two to two means rotten.

61
00:03:38,570 --> 00:03:41,600
So if this is right, then you need to push this.

62
00:03:42,830 --> 00:03:43,880
We will push this.

63
00:03:43,910 --> 00:03:47,930
So what is X coordinate I jacarandas zero and time.

64
00:03:47,930 --> 00:03:48,650
Time is zero.

65
00:03:48,830 --> 00:03:49,220
Right.

66
00:03:49,670 --> 00:03:54,860
We are starting and since we have inserted in the queue what will do we will mark.

67
00:03:54,860 --> 00:03:58,580
This has visited surveys of iji is true.

68
00:04:01,220 --> 00:04:05,380
Right, so we have done these two things, so let's remove them from here.

69
00:04:11,110 --> 00:04:11,370
Hmm.

70
00:04:12,180 --> 00:04:17,790
Now, let's move ahead, so while the queue is not empty, did our friend correct, Pop right.

71
00:04:18,269 --> 00:04:22,590
And see here, I think we need to remove this condition.

72
00:04:23,340 --> 00:04:27,170
We do not need this condition here because there is no destination.

73
00:04:27,810 --> 00:04:30,410
I don't have any destination as of now.

74
00:04:30,450 --> 00:04:30,820
Right.

75
00:04:31,260 --> 00:04:35,460
We do not have a destination cell, so we do not need this condition.

76
00:04:35,460 --> 00:04:37,890
So I need to we need to remove this condition.

77
00:04:39,180 --> 00:04:40,380
So let's remove it.

78
00:04:44,360 --> 00:04:45,920
Let's remove this condition,

79
00:04:49,920 --> 00:04:54,240
I can move in forward direction from the given cell.

80
00:04:54,260 --> 00:05:02,300
So let's move in for direction X should bigger than zero and X should be less than M, Y should bigger

81
00:05:02,300 --> 00:05:02,750
than zero.

82
00:05:02,750 --> 00:05:07,850
Y listening and grid of X, Y should be one.

83
00:05:08,210 --> 00:05:08,680
Right.

84
00:05:08,690 --> 00:05:12,290
We are only interested in the vertices, which is containing one.

85
00:05:14,610 --> 00:05:16,140
See, this is too.

86
00:05:17,790 --> 00:05:24,330
So what I am saying, I can move here, I can move here, I can move here and let's say this is zero,

87
00:05:24,660 --> 00:05:25,350
so four zero.

88
00:05:25,350 --> 00:05:26,390
This is empty cell.

89
00:05:26,430 --> 00:05:28,080
We are not interested in empty cell.

90
00:05:28,440 --> 00:05:29,880
We are only interested in once.

91
00:05:30,060 --> 00:05:31,470
So this is one what I will do.

92
00:05:31,470 --> 00:05:32,370
I will write this.

93
00:05:32,370 --> 00:05:33,420
I will make it to.

94
00:05:34,080 --> 00:05:41,760
OK, so if the adjacent cell is containing a fresh orange and that cell has not been visited, then

95
00:05:41,760 --> 00:05:44,220
visit them and in certain right.

96
00:05:46,250 --> 00:05:47,510
So we need to.

97
00:05:52,350 --> 00:06:01,380
What we need to do, we will push in the X, Y, and this is actually time, so time plus one rate and

98
00:06:01,380 --> 00:06:02,850
visited off X Y is true.

99
00:06:02,850 --> 00:06:06,120
And what we need to do, we need to mark that.

100
00:06:06,360 --> 00:06:11,990
This cell has been this fresh, orange has been returned.

101
00:06:12,000 --> 00:06:14,700
So this is too late.

102
00:06:15,840 --> 00:06:17,410
This was a fresh orange.

103
00:06:17,810 --> 00:06:20,430
Now this is a rotten orange.

104
00:06:20,430 --> 00:06:20,790
Right.

105
00:06:20,800 --> 00:06:21,960
We need to mark this.

106
00:06:21,970 --> 00:06:26,580
Now the question is how we can find out that time, right.

107
00:06:26,730 --> 00:06:28,660
That time to rot all the oranges.

108
00:06:29,190 --> 00:06:31,880
So let's say I have this variable time.

109
00:06:34,260 --> 00:06:36,230
Time is let's say it is zero.

110
00:06:37,830 --> 00:06:45,330
So virtually with the time taken to rot, all the oranges, I think the time will be the maximum of

111
00:06:45,900 --> 00:06:49,500
the current time and the time they can to rot.

112
00:06:51,400 --> 00:06:54,630
All the oranges sorted all time, right?

113
00:06:54,910 --> 00:06:56,530
Are you able to understand this line?

114
00:06:57,580 --> 00:07:00,180
Our time is mix of time and time.

115
00:07:00,520 --> 00:07:06,940
See what we need to do, what we are storing in each cell, what we are studying, etc. We are storing.

116
00:07:06,940 --> 00:07:09,330
I got it at that time.

117
00:07:09,970 --> 00:07:11,300
So what is this time?

118
00:07:11,320 --> 00:07:12,120
What is this time?

119
00:07:12,130 --> 00:07:15,790
This is the time taken to write this particular index.

120
00:07:15,790 --> 00:07:16,120
Right?

121
00:07:16,150 --> 00:07:18,130
This particular fresh orange.

122
00:07:18,310 --> 00:07:20,500
So what I am doing, I am taking Maksym off.

123
00:07:20,500 --> 00:07:21,730
All right.

124
00:07:21,970 --> 00:07:25,030
We need to take maximum rate.

125
00:07:25,510 --> 00:07:28,750
I need to find out the time to counteract all the oranges.

126
00:07:28,940 --> 00:07:33,520
So time taken to rot, all oranges.

127
00:07:34,690 --> 00:07:38,770
By the time this will be maximum time to rot

128
00:07:41,560 --> 00:07:43,150
fresh orange to rot.

129
00:07:43,150 --> 00:07:44,290
Any fresh orange.

130
00:07:45,490 --> 00:07:52,720
Right, so time they can buy all oranges will be the maximum time to rot any fresh orange.

131
00:07:53,320 --> 00:07:57,960
So that's why we need to take some here and not a minimum medium.

132
00:07:58,370 --> 00:08:01,470
But if you put them in them then they will always be zero.

133
00:08:02,440 --> 00:08:03,880
You should write maximum here.

134
00:08:03,880 --> 00:08:05,140
You must try to make some here.

135
00:08:05,380 --> 00:08:10,150
So if this thing is not clear, let me try to explain you one more time.

136
00:08:10,160 --> 00:08:10,420
Si.

137
00:08:11,230 --> 00:08:12,520
Let's take this example.

138
00:08:12,520 --> 00:08:13,510
This is one to one.

139
00:08:13,870 --> 00:08:19,660
Let's say I have one here and similarly zero zero zero litigiousness two.

140
00:08:20,230 --> 00:08:23,680
This is one one and one.

141
00:08:24,370 --> 00:08:25,780
And this Lazaro's.

142
00:08:27,160 --> 00:08:27,560
Right.

143
00:08:27,730 --> 00:08:29,470
So let's consider this case.

144
00:08:29,830 --> 00:08:31,750
So initially, the value of time is zero.

145
00:08:31,870 --> 00:08:32,890
But that is correct.

146
00:08:32,919 --> 00:08:36,520
So this is to this will not all its corresponding oranges.

147
00:08:36,909 --> 00:08:37,990
So it will read this.

148
00:08:37,990 --> 00:08:39,159
It will read this.

149
00:08:39,490 --> 00:08:39,850
Right.

150
00:08:40,150 --> 00:08:41,740
So this cell.

151
00:08:42,010 --> 00:08:42,460
Right.

152
00:08:42,789 --> 00:08:50,170
This cell is containing the energy and the time time taken to write.

153
00:08:50,180 --> 00:08:51,110
This is one minute.

154
00:08:51,450 --> 00:08:57,750
Similarly, what the cell will contain in the exchange and the time taken to write this one time taken

155
00:08:57,760 --> 00:08:59,620
was one minute late.

156
00:08:59,860 --> 00:09:03,190
And similarly, in that one minute, this will also be written.

157
00:09:03,190 --> 00:09:06,970
So IGY and again went right to this particular cell.

158
00:09:07,390 --> 00:09:08,680
So this will become two.

159
00:09:10,060 --> 00:09:13,940
Now, after one more minute, what will happen?

160
00:09:14,380 --> 00:09:17,830
So this two will draw this one, right?

161
00:09:18,040 --> 00:09:19,140
So it will write this one.

162
00:09:19,450 --> 00:09:22,720
So IJA and time to convos this time plus one.

163
00:09:23,050 --> 00:09:24,920
So time taken is two minutes for this.

164
00:09:24,980 --> 00:09:28,080
Now the system similarly this disproval, this one.

165
00:09:28,390 --> 00:09:36,540
So it will become two and this is IJI and time taken is two minutes right now after one more minute

166
00:09:36,550 --> 00:09:37,240
what will happen.

167
00:09:37,240 --> 00:09:37,810
This Trouville.

168
00:09:38,140 --> 00:09:38,430
This.

169
00:09:38,890 --> 00:09:42,490
So this will get Roatan and time taken is IJI and three.

170
00:09:43,420 --> 00:09:43,840
Right.

171
00:09:43,990 --> 00:09:47,890
So what I am doing, I am taking maximum of all these.

172
00:09:47,890 --> 00:09:49,600
I am taking maximum of all.

173
00:09:51,580 --> 00:09:54,010
I am taking here maximum of oil.

174
00:09:54,220 --> 00:09:56,050
So the output will be three.

175
00:09:56,350 --> 00:09:56,770
Right.

176
00:09:57,340 --> 00:09:58,880
So that is what I am doing here.

177
00:09:59,890 --> 00:10:03,550
So I hope I am clear now finally what you can do.

178
00:10:04,540 --> 00:10:06,150
Can I write time here.

179
00:10:06,430 --> 00:10:08,570
Can I directly written the answer time.

180
00:10:08,980 --> 00:10:10,880
No, you cannot do this.

181
00:10:11,350 --> 00:10:15,400
First you need to check whether there is any fresh orange in the grid or not.

182
00:10:16,050 --> 00:10:16,480
Right.

183
00:10:16,660 --> 00:10:23,380
First you need to check whether all the fresh oranges have been brought in or not.

184
00:10:23,710 --> 00:10:34,720
So if the grid contains any one fresh orange, that means I am not able to get all the fresh oranges.

185
00:10:34,720 --> 00:10:36,010
I will return minus one

186
00:10:39,040 --> 00:10:40,990
before returning your answer time.

187
00:10:41,240 --> 00:10:47,120
What we need to do, we need to first check whether I have written all the fresh oranges are not so

188
00:10:47,200 --> 00:10:49,120
for checking, I need to hydrate.

189
00:10:49,120 --> 00:10:50,110
So I am hydrating.

190
00:10:50,110 --> 00:10:57,820
And if there is any fresh orange present then I need to return minus one that I am not able to rot all

191
00:10:57,820 --> 00:10:58,920
the fresh oranges.

192
00:10:58,930 --> 00:11:00,600
So that will be the complete cold.

193
00:11:00,940 --> 00:11:03,800
Let's turn our cold to see if there is any back or not.

194
00:11:05,200 --> 00:11:05,660
Yes.

195
00:11:05,680 --> 00:11:07,840
So now let's salmeterol cold.

196
00:11:12,260 --> 00:11:15,770
So our goal is basically working fine, right?

197
00:11:16,850 --> 00:11:18,920
So this is the complete code.

198
00:11:20,290 --> 00:11:25,180
Very simple and very straightforward, simple algorithm.

199
00:11:26,380 --> 00:11:29,350
So actually, one of my friend interviewed with Flipkart.

200
00:11:30,360 --> 00:11:36,900
And what they did was, instead of asking for the rotten oranges, they said that zero represent basically,

201
00:11:37,410 --> 00:11:45,120
let's say, a mosque or something like that one represent basically a noncombat patient, basically

202
00:11:45,120 --> 00:11:51,420
a normal, normal person, and to represent basically a person who has covered.

203
00:11:52,230 --> 00:11:52,630
Right.

204
00:11:52,830 --> 00:11:55,760
So the question was find that.

205
00:11:55,770 --> 00:12:01,980
And again, the question was very similar, that every one minute this covid patient will make this

206
00:12:01,980 --> 00:12:04,380
normal person, also a covid patient.

207
00:12:04,380 --> 00:12:10,530
And we need to find out the number of times, I mean, a number of minutes that all the persons will

208
00:12:10,530 --> 00:12:11,700
become quite positive.

209
00:12:12,030 --> 00:12:15,000
So this question can be asked in different, different ways.

210
00:12:15,000 --> 00:12:20,640
But you should be able to figure out that this is just a variation of rotenone and just problem only.

211
00:12:20,670 --> 00:12:21,040
Right.

212
00:12:22,590 --> 00:12:24,030
So I will share the court with you.

213
00:12:24,030 --> 00:12:26,670
And this is pretty much all that I want to discuss in this video.

214
00:12:27,030 --> 00:12:28,950
So I will see you in the next one.

215
00:12:28,980 --> 00:12:29,520
Thank you.

