Skip to content

Practice Maximize Active Section with Trade I

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3499
LeetCode Problem

Maximize Active Section with Trade I

Problem Statement

In binary string s, 1 marks an active section and 0 an inactive one. You may make at most one trade: first change an entire contiguous run of ones surrounded by zeroes into zeroes, then change a contiguous run of zeroes surrounded by ones into ones. Evaluate the surrounding conditions as if a virtual 1 were added at both ends of s; those virtual positions are never counted. Return the maximum number of ones in the resulting original-length string.

Source: Maximize Active Section with Trade I on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "01"
Output
1

# Example 2

Input
s = "0100"
Output
4

# Example 3

Input
s = "1000100"
Output
7

# Example 4

Input
s = "01010"
Output
4

Constraints

1 <= n == s.length <= 10^5
s[i] is either '0' or '1'

Related LeetCode Problems

Practice more problems similar to Maximize Active Section with Trade I.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.