LC: 1151. Minimum Swaps to Group All 1's Together
https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together/
Input: data = [1,0,1,0,1]
Output: 1
Explanation:
There are 3 ways to group all 1's together:
[1,1,1,0,0] using 1 swap.
[0,1,1,1,0] using 2 swaps.
[0,0,1,1,1] using 1 swap.
The minimum is 1.Input: data = [0,0,0,1,0]
Output: 0
Explanation:
Since there is only one 1 in the array, no swaps needed.Input: data = [1,0,1,0,1,0,0,1,1,0,1]
Output: 3
Explanation:
One possible solution that uses 3 swaps is [0,0,0,0,0,1,1,1,1,1,1].PreviousLC: 1150. Check If a Number Is Majority Element in a Sorted ArrayNextLC: 1153. String Transforms Into Another String
Last updated