Your question is Minimum Swaps in Binary Array. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Given a binary array containing only 0s and 1s, find the minimum number of adjacent swaps required to rearrange it so that all 0s are at one end and all 1s are at the other end (either 000...111 or 111...000 is allowed).
Asked in the OA stage. Online Assessment DSA question.
Implement def minimum_adjacent_swaps(nums):. nums is a list of integers containing only 0 and 1. Return an integer representing the minimum number of adjacent swaps.
def minimum_adjacent_swaps(nums):