abs(a-b) can be
-a+b
a-b
a+b
-a-b
So for each value ai bi ci di and i there is 2 sign possible either + or -
so consider all combination of these signs
These are total 32 combination
U can easily generate combination by using bits like for 0 -> 00000 denotes + + + + + and
1-> 00001->+ + + + -
now for each combination calculate max and min value of this combination
Eg
For i 0 to n-1
Temp=Max(Ai-Bi+Ci-Di+i )-min(Ai-Bi+Ci-Di+i)
The max value of Temp over all combination is the answer.
Time complexity O(N*32)
i went for brute force since time limit is 5 seconds
i.e n*(n-1)/2
i.e 10^5*(10^5-1)/2
-> 5x10^4x10^5 => 5x10^9
if we consider 10^9 computations per second 5*10^9
i think it atleast give 50% of marks
but there must be better way
lets hope for the best
Don’t worry they hired for SES role . And now about your bruteforce solution . Definately it will fetch some of points like you will get at least more than half i think. As N constraints is 100000 so in worst case we need comparison is (10^5 + 10^5-1 + 10^5-2…+1) = (10^5 * (10^5+1))/2 which is nearly equal to 510^9 and our system gives time limit is 5 second so we can assume that we can iterate nearly 510^9 . So I think brute force will give definitely some points . It may fail on strictly bounded data on 10^5. @ssrivastava990 @ssjgz