WA MAXDIFF

Question link >> CodeChef: Practical coding for everyone
my solution >> CodeChef: Practical coding for everyone

IDEONE link >>KcqKSO - Online C Compiler & Debugging Tool - Ideone.com

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 >>KcqKSO - Online C Compiler & Debugging Tool - Ideone.com

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