mouryasatyam's blog

By mouryasatyam, 3 years ago, In English

Interesting Problem on Application of Stack

Hello everyone, This is my first blog entry on Codeforces. I want to share with you all an interesting problem based on application of stack. I came across the question in hiring process and have my detailed accepted solution approach and code.

Question:

Given an integer array A of length n.Find the sum of maximum of contiguous subarray times the length of the subarray for each subarray modulo 10^9+7.

Constraints:

1<= n <= 10^5
1<= A[i] <= 10^9 , 1<= i <=n

Note: Array may have duplicate elements.

sample input 1

Input
Output

sample input 2

input
output

sample input 3(important case)

input
output

Approach:

Detailed Explanation

Implementation

Time Complexity: O(n)

C++ Code
Python Code

Drop a Query or other approaches in Comment section.

Suggestions are welcomed.

Full text and comments »

  • Vote: I like it
  • +14
  • Vote: I do not like it