ORIGINAL CODING QUESTION
Product budget windows
Count nonempty contiguous segments whose product is strictly below k.
Original exercise · medium. Editorial role relevance does not imply a company has asked this question.
Input and output
n, then n positive integers, then k.
Constraints
1 ≤ n ≤ 30; 1 ≤ value ≤ 10; 0 ≤ k ≤ 10,000. Stop multiplying once a product reaches k.
Example 1
Input
4 10 5 2 6 100
Output
8
Eight segments have product below 100.
Example 2
Input
3 1 1 1 1
Output
0
No positive product is below 1.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
Handle k≤1 first.
Hint 2
All values are positive so extending cannot decrease the product.
Hint 3
After shrinking to a valid window, count all segments ending at the right boundary.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →