#3501
Maximize Active Section with Trade II
grandmaster · 2205 · lc hard +32 · 20.5% accepted · 24 likes · top 2%
Description
Binary string s marks sections as active (\'1\') or inactive (\'0\'). For each query [li, ri], apply at most one trade to substring s[li...ri]:
- Flip a \'1\'-block surrounded by \'0\'s to all \'0\'s.
- Then flip a \'0\'-block surrounded by \'1\'s to all \'1\'s.
Return the maximum active count for each query as array answer.
Note: Each query treats its substring as padded with \'1\' on both ends; those padding characters are excluded from the count. Queries are independent.
Code
1
2
3