Algorithm · Amazon · Medium
Minimum Swaps to Group a Binary Array Medium · Topics · Company Tags · Hints You are given a binary array arr consisting solely of 0s and 1s. In a single move, you may select any two neighboring elements and exchange their positions. Your objective is to transform the array into one of two ordered arrangements: All 0s followed by all 1s (i.e., 000...111) All 1s followed by all 0s (i.e., 111...000) Determine the minimum number of adjacent swaps required to reach either target…
Checking your access…