problem link:-SALARY Problem - CodeChef

My solution:-CodeChef: Practical coding for everyone

you are taking the min wrong first you are making mn=ar[0] then checking

consider the array 3 2 5 6 your code will return min as 3 but actual min is 2 and also the way you are calculating the ans is wrong as max can change when you increment the other salaries as salaries can be equal so you need to sort the array and add max-min (max=ar[n-1],min=ar[0]) to all the elements from 0 to n-2 as ar[n-1] would be the max add max-min to ans while max!= min then print ans

1 Like