Infosys Q2 - OA - Pls Provide Solution
Anonymous User
200

Given an array , take 2 elements of a[i] and a[j] and take difference of a[i]-a[j] or
a[j]-a[i] for i!=j and delete both elements and place the difference back into array and keep taking difference until we have one element in array with maximum possible value.

Arrays can contain negative and positive values.

input form : space separated integers of an array
ouput : max value of differences until one element

INPUT 1:
-5 3 -4 -2 -2
OP : 16

INPUT 2:
3 -3 2 -6 2 -1
OP:17

INPUT 3:
1
OP:1

INPUT4:
-2 -4 -6 -8
OP: ?

Comments (0)