title: Find number of contiguous subarrays with all intermediate numbers less than the two endpoints
body: <p>Given an array of integers, I would like to find the number of subarrays that satisfy the condition that all intermediate values are less than the minimum of the two endpoints. I know that it is possible to do this in O(log(n) + n^2)(try every pair with the help of a sparse table), but am curious as to if it is possible with lower complexity.</p>
  <p>Example: [3, 4, 6, 1, 5, 9]
  Valid start and end values in the this scenario would be (3, 4), (4, 6), (6, 1), (6, 5), (6, 9), (1, 5), and (5, 9)</p>