Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
Search
⌘K
Get Premium
Leetcode 3501. Maximize Active Section with Trade II
For each query substring (augmented with a '1' at both ends), compute the maximum number of '1's obtainable by doing at most one "trade" that replaces an internal run of 1s (surrounded by 0s) with 0s and then flips an internal run of 0s (surrounded by 1s) to 1s. The core challenge is to pick runs to maximize net gain in ones for each query — solvable by run-length encoding plus range-query preprocessing (e.g., segment trees or sparse tables) to evaluate best trade quickly.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.