MediumRating 1940
2762. Continuous Subarrays
arrayqueuesliding-windowheap-priority-queueordered-setmonotonic-queue
解題說明
C++ 解法
複雜度分析
虛擬碼
1. Initialize left = 0, two deques (maxQ for max, minQ for min)
2. For each right from 0 to n-1:
a. Add right to maxQ (maintain decreasing order)
b. Add right to minQ (maintain increasing order)
c. While max - min > 2:
- Advance left
- Remove expired indices from both deques
d. Add (right - left + 1) to answer
3. Return answer