#3499
Maximize Active Section with Trade I
expert · 1125 · lc medium +32 · 31.3% accepted · 69 likes · top 9%
Description
Binary string s uses \'1\' for active and \'0\' for inactive sections. Perform at most one "trade":
- Turn a block of \'1\'s surrounded by \'0\'s into all \'0\'s.
- Then turn a block of \'0\'s surrounded by \'1\'s into all \'1\'s.
Return the maximum number of active (\'1\') characters after the optimal trade.
Note: Treat s as padded with \'1\' on both ends (t = \'1\' + s + \'1\'); these padding characters do not count toward the total.
Code
1
2
3