Quant Memo
Coding/●●●●

Count price windows whose product stays under a cap

Given a list of positive numbers, count how many contiguous subarrays have a product strictly less than k. Think of the values as growth factors and k as a compounding cap.

nums = [10, 5, 2, 6], k = 100
-> 8

The 8 valid windows include [10], [5], [2], [6], [10,5] (50), [5,2] (10), [2,6] (12), and [5,2,6] (60).

Return the count of subarrays with product < k, in O(n) time.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions