Maximum value in an array

problem link-https://hack.codingblocks.com/contests/c/509/197
my code-https://ide.codingblocks.com/#/s/28412
My code is showing ‘wrong answer’ in test case 3.

Actually you intitialize MaxVal=0
But think of array like {-1,-2,-3)
it has got max value as -1
So that’s why you are not passing test case

Try replacing
int MaxVal=0;
with
int MaxVal=INT8_MIN;

it is the minimum value of integer

1 Like