Hello everyone, recently I was giving an OA in a company and this problem came up.
Problem: You are given an array A containing N positive integers. The task involves calculating the special value of the array. The special value (S) is sum of product of smallest and largest number of all the possible subarray of A. Find the special value (S) of A. Since the answer can be very large return it modulo 10^9+7.
Constraints: 1 <= N <= 10^5, 1 <= A[i] <= 10^9
Test Case 1: A = [1,4,2] Ans = 37
Test Case 2: A=[1,2] Ans = 7
Test Case 3: A = [2,2] Ans = 12
Can anyone explain me the approach to solve this. Thanks in advance.



