Computer Science, asked by LuciferJais, 1 month ago

Optimize solution in cpp?


You are given a sequence A1,A2,…,AN. Find the maximum value of the expression |Ax−Ay|+|Ay−Az|+|Az−Ax| over all triples of pairwise distinct valid indices (x,y,z).

Answers

Answered by aerma7309
17

Answer:

2*(max of seq - min of seq)

Explanation:

Answered by shawnmoses1847
17

Answer:

2 * (max - min)

Explanation:

u want to maximise the difference, therefore u take the max and min as x and y, assume the other value is R : min<R<max

now u have..

max - min + R-min + max - R

=> max + max -min -min

=> 2*(max - min)

Similar questions