Algorithm · Amazon · Medium
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 configuration. Implement a function minSwaps(arr) that computes and returns…