Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

Блог пользователя mouryasatyam

Автор mouryasatyam, 3 года назад, По-английски

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.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +14
  • Проголосовать: не нравится