Data Structures19 sections · 729 units
Open in CourseQuiz: DP Optimization
When deques help
Check Your Understanding
A DP recurrence is dp[i] = max(dp[i-1], dp[i-2], ..., dp[i-k]) + cost[i]. What's the time complexity with a monotonic deque?
- A.O(k) - constant per state
- B.O(n log k) - using a heap
- C.O(nk) - same as naive
- D.O(n) - each index enters and leaves deque once