What’s wrong with this approach for The Biggest Restaurant?
I am sorting both x and h
To get the maximum ans i am making h sequence something like this in alternative fashion:
if h = {1,2,3,4} → nh = {1,4,3,2}
h = {1,2,3,4,5} → nh = {1,5,3,4,2}
h = {1,2,3,4,5,6} → nh = {1,6,3,4,5,2}
and so on i formed a sequeunce by this logic.
Then i just calculated area of triangle and square of two consecutive points while traversing.
Apply trapezium area formula not triangle + rectangle or square
And after making right arrangement for height we need to find the greatest difference of heights that is points on x axis. Therefore the maximum sum(sum of columns) will be multiplied to maximum difference of two consecutive points .
And the arrangement of columns can be in this way for maximum
{2,4,6,5,3,1}
That means each element of sorted array of sum of adjacent heights and sorted array of difference of adjacent heights will be multiplied and added to give answer?