Amazon OA
Anonymous User
7599

Get the sum of min and max diff for all subarrays

[2,4,3,5]

wrong: sum = (4 - 2) + (4 - 3) + (5 - 3) + (3 - 2) + (5 - 4) + (5 - 2) = 10

sum = (4 - 2) + (4 - 3) + (5 - 3) + (4 - 2) + (5 - 3) + (5 - 2) = 12

O(n2) exceeds time limit

Not sure how to optimize to be < O(n2)

Comments (13)