mediumEnumerationString 0 views

Maximize Active Section with Trade I

You are given a binary string s of length n, where: You can perform at most one trade to maximize the number of active sections in s.

You are given a binary string s of length n, where:

You can perform at most one trade to maximize the number of active sections in s. In a trade, you:

Return the maximum number of active sections in s after making the optimal trade.

Note: Treat s as if it is augmented with a '1' at both ends, forming t = '1' + s + '1'. The augmented '1's do not contribute to the final count.

Maximize Active Section with Trade I diagram

Example 1

Input: s = "01"

Output: 1

Explanation: Because there is no block of '1' s surrounded by '0' s, no valid trade is possible. The maximum number of active sections is 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'

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.