Trains the technique from
LeetCode 3501Maximize Active Section with Trade IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A shop sign is a strip of segments described by strip, where '1' is a segment that is lit and '0' is one that is dark.
Each entry queries[j] = [lo, hi] asks about the stretch of segments from lo to hi inclusive. The queries are independent: the strip itself is never changed, and every query starts from the strip as given.
Within the stretch a technician gets one repair pass, whose two steps are taken in this order.
The two runs need not be the same length, either may be empty, and neither may reach outside the stretch. The steps cannot be reordered or repeated.
Return an array best where best[j] is the largest number of lit segments the j-th stretch can show once its pass is over.
Example 1
For the whole strip, switching nothing off and switching the three dark segments on shows seven lit segments. For the stretch from 2 to 4 every segment is dark, and switching all three on shows three. For the stretch from 0 to 3 the two dark segments can be switched on, showing four.
Example 2
Across the whole strip, switching off the lit segment at position 3 leaves seven dark segments in a row, and switching them all on shows seven lit segments. The stretch from 2 to 4 reads lit, dark, lit and can show three. The stretch from 1 to 5 can show five.
Example 3
Every segment is already lit, so the best pass switches nothing off and nothing on.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def best_lit_in_window(strip: str, queries: list[list[int]]) -> list[int]:public List<Integer> bestLitInWindow(String strip, int[][] queries)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.