Dynamically expands right edge to satisfy constraints and contracts left edge to find optimal subarrays.