Amazon OA Question - Is there an O(n)
Anonymous User
8804

Given an array "points" of numbers, a score can be calculated for a subarray [i....j] by...

score = min(points[i...j])*sum(points[i...j[)

return the sum of all scores of all possible subarrays.

For example, points = [2,1,3]
in the form index pair = score
0,0 = 4
0,1 = 3
0,2 = 6
1,1 = 1
1,2 = 4
2,2 = 9

total = 25

I completely blanked and only managed n^2, I feel like I'm being stupid and missing a really obvious O(n). Anyone?

Comments (12)