What did you learn? When DP transitions look at the last states, monotonic deques can optimize from to .
You've learned a general pattern. Any DP where you need or over a sliding window of previous states can use this technique.
The deque stores indices into the DP array, ordered by DP values. This optimization appears in advanced DP problems. Recognize the pattern: "max/min over previous states."