WEBVTT

00:01.300 --> 00:01.810
Hi everyone.

00:01.810 --> 00:03.070
Welcome back to this tutorial.

00:03.070 --> 00:10.780
In this tutorial, we'll code and learn how to perform the min operation of a list of integers in a

00:10.780 --> 00:11.440
stream.

00:11.440 --> 00:15.370
So here we talked about the max in the previous tutorial.

00:15.370 --> 00:17.410
I'm going to use the same example here.

00:17.440 --> 00:22.840
The first thing is I want to show the difference between with the identity and without the identity

00:22.840 --> 00:23.560
value.

00:24.220 --> 00:28.450
I'm going to copy the same code and then paste it here.

00:28.480 --> 00:31.030
It's going to be named as min min value.

00:31.450 --> 00:33.640
I'm going to comment this whole max part.

00:33.670 --> 00:34.750
I don't want this.

00:35.590 --> 00:38.410
Because I don't I'm not going to use this as part of this tutorial.

00:38.560 --> 00:41.320
Now, let me put this in presentation mode.

00:46.210 --> 00:50.110
Then here we are going to talk about the min value so far, the max value.

00:50.140 --> 00:54.910
What we did was we used the greater than for this.

00:54.940 --> 00:58.210
We are just going to change this one to less than.

00:58.570 --> 00:59.380
Let's talk about it.

00:59.380 --> 01:00.850
What happens behind the scenes.

01:00.850 --> 01:08.080
So here six is going to be assigned against the Y variable here and X is going to hold the result of

01:08.080 --> 01:08.680
it, right?

01:08.680 --> 01:13.810
So for the first time, what it is going to do, it is going to assign zero.

01:14.020 --> 01:21.400
That is the initial value against the X variable and then Y is going to hold six for the first element

01:21.400 --> 01:26.950
in the string because we know string is going to pass the elements one by one and then is zero less

01:26.950 --> 01:27.850
than six.

01:28.270 --> 01:32.110
So here is a condition which we which we have is a zero less than six.

01:32.110 --> 01:32.440
Yes.

01:32.470 --> 01:37.360
In that case X will be assigned with zero value for the next element.

01:37.540 --> 01:44.380
Seven is again, seven is set against the y variable is zero less than seven.

01:44.380 --> 01:45.070
Yes.

01:45.070 --> 01:49.100
And then it is going to assign the zero as a minimum value.

01:49.100 --> 01:54.560
It is going to continue until all the elements in the stream are passed as part of the iteration.

01:54.560 --> 01:59.300
What I'm going to do, I'm going to call this method and then check what is the result that it is going

01:59.300 --> 01:59.810
to give.

02:00.470 --> 02:05.210
So int min value equal to.

02:06.420 --> 02:08.850
Find min value and then pass integer list.

02:10.790 --> 02:14.870
You're going to be surprised by looking at the result because.

02:16.000 --> 02:17.710
We'll get to know about that in a bit.

02:20.800 --> 02:21.610
Run this.

02:23.040 --> 02:28.800
So the output that we're expecting is six, but the result that we got is zero.

02:28.830 --> 02:29.650
Why?

02:29.670 --> 02:34.800
If we take a look at it, we have the default value, which is set to zero.

02:34.890 --> 02:39.750
That is going to be the least value compared to all the elements in the string.

02:39.870 --> 02:40.530
Right.

02:40.530 --> 02:45.660
So this is something which we have to keep in our mind when you are calculating the min value.

02:45.690 --> 02:48.960
You should never, ever use the default value.

02:49.160 --> 02:53.220
So I'm going to remove this and then let's change this one to optional.

02:55.830 --> 02:56.730
Same concept.

02:57.340 --> 03:00.540
And then I'm going to copy this and put it here.

03:01.970 --> 03:03.650
I'll be minvalue.

03:04.910 --> 03:05.450
Optional.

03:06.430 --> 03:08.560
And then now the drill.

03:09.840 --> 03:12.150
Going to print the mean value optional.

03:15.370 --> 03:23.380
Here the f min value dot is present, then I will get the value and then printed this out.

03:26.660 --> 03:29.360
The minimum value is.

03:33.220 --> 03:35.740
Minvalue optional dot get.

03:36.640 --> 03:40.990
Good action is else going to print?

03:43.700 --> 03:44.720
No input is.

03:48.220 --> 03:50.330
Now let's run this and check.

03:50.350 --> 03:53.530
So we are we're calling the find min value.

03:53.530 --> 04:00.760
It is taking a list is iterating, and then it is going to apply each and every value in the stream

04:00.760 --> 04:05.320
to the Y variable, and X is going to hold the result as the.

04:07.270 --> 04:08.140
X variable.

04:08.230 --> 04:11.180
So in here, let's run this and check.

04:11.200 --> 04:14.080
So the value that I'm expecting is six.

04:16.560 --> 04:17.580
We take a look at it.

04:17.610 --> 04:18.620
The value is six.

04:18.630 --> 04:20.400
Let's say I'm passing an empty list.

04:20.430 --> 04:21.510
What will happen?

04:22.350 --> 04:24.150
Empty list is going to.

04:25.630 --> 04:28.090
Print the result as no input is passed.

04:28.540 --> 04:29.030
Take a look at it.

04:29.050 --> 04:31.720
No input is passed and the optional value is.

04:33.430 --> 04:41.290
So this is one of the approach of calculating the min value using the reduce function.

04:42.190 --> 04:48.520
So this is all about how to calculate the max and min value from a stream of integers.

04:48.700 --> 04:53.590
You can just do it for any kind of other number types.

04:53.860 --> 04:55.150
Double long.

04:55.300 --> 04:56.500
The same approach.

04:57.600 --> 04:59.610
But thus we came to the end of this tutorial.

04:59.640 --> 05:00.720
Thank you for watching.
