Access denied to your solution- please re-check link.
Anyways, one of the corner case was that -You have to sort the weights, and check which is giving more difference- taking first K elements or taking last K elements.
I’v updated the link… I am sorting the array first and then checking the difference…
You are doing the same mistake which I stated.
The difference can be max by either taking first K elements, or last K elements.
Eg, take this example-
For K=1, here the difference is greatest on taking only first element, diff=(1000+1+1)-1=1001. Now look at next example-
Taking first 4 elements gives us 3001-1000=2001. Taking last 4 elements gives us 4000-1=3999.
I think you get the point now
Yes THanks again!
what is wrong with my code here?