Tap here to switch tabs
Problem
Submissions

Problem: Maximize Active Section with Trade I

Maximize Active Section with Trade I gives a binary string and permits at most one trade: choose a block of ones flanked by zeros, convert its maximal zero neighbors, and return the most ones.

Statement

You are given a binary string s of length n. Each character '1' in s represents an active section.

You are allowed to perform at most one trade operation:

  • Select a contiguous substring of '1's that is immediately flanked by '0's on both its left and right sides.

  • Let AA be the maximal contiguous block of '0's immediately to the left of the selected substring, and let BB be the maximal contiguous block of '0's immediately to its right.

  • The trade operation converts all characters in both AA and BB into '1's.

Return the maximum number of active sections in s after performing at most one trade operation.

Constraints:

  • 1≤n==1 \leq n == s.length ≤105\leq 10^5

  • s[i] is either '0' or '1'

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximize Active Section with Trade I

Maximize Active Section with Trade I gives a binary string and permits at most one trade: choose a block of ones flanked by zeros, convert its maximal zero neighbors, and return the most ones.

Statement

You are given a binary string s of length n. Each character '1' in s represents an active section.

You are allowed to perform at most one trade operation:

  • Select a contiguous substring of '1's that is immediately flanked by '0's on both its left and right sides.

  • Let AA be the maximal contiguous block of '0's immediately to the left of the selected substring, and let BB be the maximal contiguous block of '0's immediately to its right.

  • The trade operation converts all characters in both AA and BB into '1's.

Return the maximum number of active sections in s after performing at most one trade operation.

Constraints:

  • 1≤n==1 \leq n == s.length ≤105\leq 10^5

  • s[i] is either '0' or '1'