Search
⌘K

Leetcode 3499. Maximize Active Section with Trade I

Given a binary string (treated with implicit '1' at both ends), you may perform at most one trade that flips an internal contiguous run of 1s (surrounded by 0s) to 0s and an internal contiguous run of 0s (surrounded by 1s) to 1s; compute the maximum number of 1s obtainable. The core challenge is to scan the run lengths and pick the pair (1-run removed, 0-run added) that maximizes the net gain in ones (n up to 1e5).


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.