Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
We can use sliding window and binary search.
For each index <code>r</code>, find the maximum <code>l</code> such that both conditions are satisfied using binary search.