problem- https://www.codechef.com/COOK111B/problems/MDL

Here is my solution

https://www.codechef.com/viewsolution/27528721

whats the mistake?

Initialization of min,max is wrong. Init min = 120 and max = 0. It will work.

- They didn’t tell array will be in decreasing order for you to do such initializations. Otherwise logic seems crct.

Hey @pratyaksh123 !

The problem here is you are assigning min and max variable wrongly before doing the for loop

do one thing :

#define INF 0x3f3f3f3f3f

after you write : using namespace std

( this is the infinity value)

and then do :

min = INF;

max = -INF;

This is how you calculate the minimum and maximum

This will work

Sudheera Y S

Even this wont work as you are not sorting the array

xactly [They made post needs to be 10 characters from 20 characters] [Still no good :P]

Better to do INF and -INF I guess

Will work. But Keeping min = 110 and max = 0 is more understandable for beginners. Because any element of Ai won’t exceed 109 and they will understand what is the intent behind initializing them.

yeah got correct submission , but even with previous code i was getting same.

Why we define min = INF max = -INF like that ?

sorry for silly doubts

See , we are looking for minimum number in the array then we will do min( least , a[i]) right , so before you start the for loop you are initialising the value of min to -INF then after the first i in the for loop the value will be the number itself and then we can keep on doing the min and then after the for loop ends it will be the least element

-INF is just to make sure we have the smallest element even if there are negative elements in the array

same for max also

Sudheera Y S

thanks got it !