1061. Number of Valid Subarrays

Hard
Array
Stack
Monotonic Stack

Description

Hints

Hint 1
Given a data structure that answers queries of the type to find the minimum in a range of an array (Range minimum query (RMQ) sparse table) in O(1) time. How can you solve this problem?
Hint 2
For each starting index do a binary search with an RMQ to find the ending possible position.

Statistics

Acceptance
79.8%
Submissions
23,162
Accepted
18,479