Hi, I recently appeared for Amazon OA which consisted 2 questions, one was quite easy and straighforward on Pascal's encryption of a string. Second was a bit tricky and based on the constraints I needed to code O(nlogn) if not O(n) solution.
Min-Max Product
You are given an array, you need to find sum of powers of all contigous sub-array, where power[i, j] is the power of sub-array starting from ith position till jth position and is defined as below :

For example :
array = [2, 4, 3, 1, 2, 4, 8]
power[0, 3] = min(0...3) x summation(0...3)
power[0, 3] = min (2, 4, 3, 1) x (2 + 4 + 3 + 1)
power[0, 3] = 1 x 10 = 10We will do this for all the contiguous sub-arrays and at the end print the sum of all such powers.
final_ans = power[0, 0] + power[0, 1] + power[0, 2] + ... + power[1, 1] + power[1, 2] + power[1, 3] + ... + power[2, 2] + power[2, 3] + ...
final_ans = final_ans % 1000000007It was a bit hard for me tbh, couldn't think of anything above the obvious brute-force. Would love to know the approaches here. Thanks!