Investable Periods

Problem Overview

  • Count subarrays (consecutive days) where the maximum equals max_price and the minimum equals min_price.
  • Input: array price of length n, and integers max_price and min_price; Output: long count of investable periods.
  • Constraints: 1 ≤ n ≤ 1e5, 1 ≤ price[i] ≤ 1e9, 1 ≤ min_price ≤ max_price ≤ 1e9.
  • Context: trading firm forecasting commodity prices seeks periods meeting exact min and max bounds.
  • From Mathworks interviews; this interview question is a classic coding interview problem on subarrays.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: