Install our extension to search inside any video instantly.

LeetCode Practice - Daily problem & Virtual Contest

Added:
791 views24likes3:07:06midnight_simonOriginal Release: 2026-07-21

Given a binary string where 1 represents an active section and 0 represents an inactive section, you can perform at most one trade to maximize the number of active sections. A trade consists of two operations: first, convert a contiguous block of ones surrounded by zeros to all zeros, then convert a contiguous block of zeros surrounded by ones to all ones. The optimal strategy involves treating the string as augmented with ones at both ends, then finding the longest streak of zeros that contains exactly one group of ones inside it. The maximum number of active sections equals the original count of ones plus the length of this longest zero streak minus the length of the smallest group of ones within it, minus 2 (to account for the augmented boundary ones).