Company: Publicis Sapient
Difficulty: medium
Minimum Swaps for Even-Odd Partition Problem Description In an array, we can swap the elements at any two indices in a single operation called a move. For example, if our array is a = [17, 4, 8] , we can swap a[0] = 17 and a[2] = 8 to get a = [8, 4, 17] in a single move. We want to custom-sort an array such that all of the even elements are at the beginning of the array and all of the odd elements are at the end of the array. For example, if our array is [6, 3, 4, 5] , then the following four arrays are valid custom-sorted arrays: a = [6, 4, 3, 5] a = [4, 6, 3, 5] a = [6, 4, 5, 3] a = [4, 6, 5, 3] Complete the function moves in the editor below. The function must return the minimum number of moves it takes to sort an array of integers with all even elements at earlier indexes than any odd element. The function moves has the following parameter: a[a[0]...a[n-1]] : an array of positive integers Note: The order of the elements within even or odd does not matter. Input Format for Custom Te