WA MAXDIFF

Question link >> https://www.codechef.com/FLMOCK01/problems/MAXDIFF
my solution >> https://www.codechef.com/viewsolution/29786955

IDEONE link >>https://ideone.com/KcqKSO

the link is coming as access denied because it’s from the CCDSAP exam submissions post an IDEONE link then! or submit your answer on the problem on the problem page and then send the link here!

IDEONE link >>https://ideone.com/KcqKSO

okay so it’s not necessary for max to be in n or n-k.
https://www.codechef.com/viewsolution/29792867
modified your solution to get AC.
First thing
if max<min, then your answer will be negative so you need to use

abs()

to get absolute value of the answer and also you need to make sure check for either the first k values or last k values.(whichever is smaller)
hence i checked it using this line:

if(k>n-k)
    k=n-k;

and it works

1 Like

thanks bro

1 Like