Tap here to switch tabs
Problem
Submissions

Problem: Minimum Swaps to Move Zeros to End

Minimum Swaps to Move Zeros to End asks for the fewest swaps needed to rearrange an integer array so every nonzero value comes before all zeros. Each swap may use any two indices.

Statement

Given an integer array nums, return the minimum number of swap operations required to move all 00’s to the end of the array such that all non zero elements appear before all 00 elements.

In a single swap operation, you can choose any two indices and swap their values.

Constraints:

  • 1≤1 \leq nums.length ≤100\leq 100

  • 0≤0 \leq nums[i] ≤100\leq 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Swaps to Move Zeros to End

Minimum Swaps to Move Zeros to End asks for the fewest swaps needed to rearrange an integer array so every nonzero value comes before all zeros. Each swap may use any two indices.

Statement

Given an integer array nums, return the minimum number of swap operations required to move all 00’s to the end of the array such that all non zero elements appear before all 00 elements.

In a single swap operation, you can choose any two indices and swap their values.

Constraints:

  • 1≤1 \leq nums.length ≤100\leq 100

  • 0≤0 \leq nums[i] ≤100\leq 100