 Hello, friends. I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to explain how you can find out maximum and second maximum from an app. So I will be implementing this solution with that proxy programming so that you can understand the logic. Before starting just one update, if you want to watch more programming related videos. So you can go to detail or description of this video. So there you will find links of various players. So you can follow them as well. So now I'm going to write the explanation or you can say I'm going to write the program and then I will be explaining how you can find out maximum and second max. So this is our array. Let's say it's size is 15. I'm declaring two variables max and s max. Both are initially zero and one variable. Then I'm going to read array from user. So these are the building steps that we need to write because if we don't read any value, we cannot perform an operation. So this way you can see 15 elements will be available inside this array. Inside this array, I'm going to apply some different conditions so that we can identify which is max and which is max. So let's say I'm declaring this array and it is having values as this. So these are some random values that I provided 15, 27, 20 and 13 and so on. So total 15 blocks will be there and different values will be there. So now after this scanner, I'm going to write if condition if a of i is greater than max. So if any element is greater than value of max, then the value which is available in max will go to s max and max will be having the value of here. Right. So this is the new number. This is the new number which is compared with max. So if new number is greater than max, it means the current max will become the second max. So I assigned value of max into s max and then this new number is now the new maximum. So this is first segment. Now I'm applying else if so if a of i is greater than if a of i is greater than second max and a of i not equals to max and a of i not equals to max, then we can assign. A of i into s max. Right. So this way this group will complete here after completion of loop. I can print both on output screen. So this way maximum and second maximum will be printed on output screen with the help of this printer after termination of loop. So now I'm going to explain this logic with the help of this example. So initially you can see max is zero and second max is also zero. So now let's say user entered 15 first time. So we need to check this logic for a zero a zero position is 15. So 15 is compared with max. So it is true because max is zero. So it means max will assign its value to s max. So max is zero. So s max will remain zero, but a of i is 15. So 15 will be assigned to max. So new value of maximum is 15. Right. And if it is true, then this else part will not work and I will be implemented. So again, we need to read new number that will be available in AI. So let's say new number is 20. Now, new number is available in AI. That is 20 max is 15. So again, this condition is true. So right now, which is the current max that is 15. So now it will become the second max. So we are assigning max into s max. So s max will be 15 and a of i is having 20. So 20 will go to max. So if new max is 20 and old max is 15. So you can see now 15 is available at second max position and new max is now 20. Right. So if again, a new number is available that is greater than max. Again, new number is available that is greater than max. Let's say 15. So 20 will become second max and that 50 will become max. Now again, I will be implemented. So next input number is next input number is seven. So let's say we are combining the seven with max. So seven is not greater than 20. Also check this a of i is greater than s max. No, seven is not greater than 15. So this is also false. So if you provide any value which is less than max as well as less than second max. So no operation will be performed. Right. So now in place of this 20. Let's say I am putting 18 here and then I am putting 20. Right. So next input number is 18. Now check a of i is 18 and max is 20. So it is false. So check a of i. So a of i is 18. 18 will be compared with s max. So what is the value of s max? That is 15. So 18 is greater than 15. So now you understood why I put 18 because 18 is greater than s max but less than max. So this value is between max and second max. So this condition is true. 18 is greater than 15 and 18 is not equals to max. So a of i is having 18 and max is having 20. So 18 is not equals to 20. So this, these both conditions are true. So a of i will be assigned into s max. So a of i is 18. It will be assigned into max. So max will become now 18. Right. Now let's say you provided next value as 20. So which is equivalent to max, which is equivalent to max. So this condition will be false because a of i is 20. Max is also 20. So it will not work. Now we come here a of i is 20, which is greater than max. It is true. So let's say if we don't write this, if we don't write this. So this 20 will be assigned into s max. So in that case max and s max both will be same. So now I hope you understood why I mentioned this condition. So if new element of array is not equals to max or you can say if this condition is false, if this condition is false and new value of array is greater than second max, but it is equal to max that you don't need to execute this. So here you can see a of i is 20. S max is 18. So this part is true, but a of i is not equals to max. a of i is 20 and max is also 20. So 20 not equals to 20. So this piece is false because both are equal. So this part will not perform. So s max will be holding on the 18. So if you try to put max repeatedly as same value, so that value will not go to second max. So second max and max both will be having different values. So after completion of this loop, max and second max will be printed on output screen as output. So I hope you understood how we can find out max and second max with the help of this project. And if you want to watch more programming related video, you can open my channel, go to playlist. So there you can find videos. Also you can go to detail or description of this video. And there also you will find links of various place and you can watch them. And I hope you understood whatever I explained in this video. So thank you for watching this video.