diff --git a/src/problem_2271_maximum_white_tiles_covered_by_a_carpet/sliding_window.rs b/src/problem_2271_maximum_white_tiles_covered_by_a_carpet/sliding_window.rs index aeaaa776..3b808259 100644 --- a/src/problem_2271_maximum_white_tiles_covered_by_a_carpet/sliding_window.rs +++ b/src/problem_2271_maximum_white_tiles_covered_by_a_carpet/sliding_window.rs @@ -35,7 +35,14 @@ impl Solution { } covered += right_end - right_start; - result = result.max(covered - right_end.saturating_sub(left_start + carpet_len)); + + let candidate = covered - right_end.saturating_sub(left_start + carpet_len); + + if candidate == carpet_len { + return candidate as _; + } + + result = result.max(candidate); } result as _