Tap here to switch tabs
Problem
Submissions

Problem: Minimum Swaps to Group All 1's Together

Minimum Swaps to Group All 1's Together gives you a binary array and asks for the fewest swaps needed to place every 1 in one contiguous group anywhere in the array.

Statement

Given a binary array data, return the minimum number of swaps required to group all 11’s present in the array together at any position.

Constraints:

  • 1≤1 \leq data.length ≤105\leq 10^5

  • data[i] is either 00 or 11.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Swaps to Group All 1's Together

Minimum Swaps to Group All 1's Together gives you a binary array and asks for the fewest swaps needed to place every 1 in one contiguous group anywhere in the array.

Statement

Given a binary array data, return the minimum number of swaps required to group all 11’s present in the array together at any position.

Constraints:

  • 1≤1 \leq data.length ≤105\leq 10^5

  • data[i] is either 00 or 11.