Company: Snowflake
Difficulty: medium
Custom-Sorted Array Problem Description In an array, elements at any two indices can be swapped in a single operation called a move. For example, if the array is arr = [7, 4, 8, 3] , swap arr[0] and arr[2] to get arr = [8, 4, 7, 3] in a single move. Determine the minimum number of moves required to 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. Examples For arr = [6, 3, 4, 5] The following four arrays are valid custom-sorted arrays: a = [6, 4, 3, 5] a = [6, 4, 5, 3] a = [4, 6, 3, 5] a = [4, 6, 5, 3] The most efficient sorting requires 1 move: swap the 4 and the 3. Complete the function moves in the editor below. moves has the following parameter(s): int arr[n] : an array of positive integers Returns int : the minimum number of moves it takes to sort an array of integers with all even elements at earlier indices than any odd element. Note: The order of the elements within even or odd does not ma