This problem gives the impression of being difficult but is actually pretty chill. 🗿
The test cases make it look like you need some complex backtracking stuff, but it’s just sliding window.
We move over the window and once product reaches over , we start shrinking from the pointer. This code snippet is very common in dynamic sliding window patterns, you would see a lot of them.
Code:
Python3
Big O Analysis
-
Runtime
The runtime complexity here is since we are visiting all elements once.
-
Memory
The memory usage is .
— A