Search
⌘K

Leetcode 1151. Minimum Swaps to Group All 1's Together

Given a binary array, find the minimum number of swaps required to make all 1's contiguous by grouping them together; this reduces to locating a subarray of length equal to the total number of 1's that contains the fewest zeros (sliding-window pattern).


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.