Practice Maximize Active Section with Trade II
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
The binary string s uses 1 for active sections and 0 for inactive ones. For each inclusive query [l, r] independently, you may perform at most one trade entirely inside that substring: turn a run of ones surrounded by zeroes into zeroes, then turn a run of zeroes surrounded by ones into ones. Treat the substring as having a virtual 1 at each end when checking these conditions. Return the maximum number of ones in the whole string s after that query’s trade; positions outside the query remain unchanged and virtual positions are not counted.
Source: Maximize Active Section with Trade II on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s = "01", queries = [[0,1]]
[1]
# Example 2
s = "0100", queries = [[0,3],[0,2],[1,3],[2,3]]
[4,3,1,1]
# Example 3
s = "1000100", queries = [[1,5],[0,6],[0,4]]
[6,7,2]
# Example 4
s = "01010", queries = [[0,3],[1,4],[1,3]]
[4,4,2]
Constraints
Related LeetCode Problems
Practice more problems similar to Maximize Active Section with Trade II.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.