Question: /* * Complete the 'minMoves' function below. * * The function is expected to return an INTEGER. * The function accepts INTEGER_ARRAY avg as parameter.

There are a number of students standing in a single-file line. Each student is numbered sequentially from O. Each student alsThere are a number of students standing in a single-file line. Each

/* * Complete the 'minMoves' function below. * * The function is expected to return an INTEGER. * The function accepts INTEGER_ARRAY avg as parameter. */

int minMoves(vector avg) {

}

There are a number of students standing in a single-file line. Each student is numbered sequentially from O. Each student also has a binary digit associated with them, where 0 indicates the student's performance is above average and 1 indicates the student's performance is below average. The teacher wants to group the students by performance on opposite ends of the line such that the number of adjacent pairs of students where one student is a 0 and the other student is a 1 is minimized. To accomplish this, any student can swap places in line with the student located immediately in front of or behind them. Each time a pair of students swaps places, it counts as a move. Determine the minimum number of moves needed to create an optimal configuration. For example, there are n=4 students arranged as avg=[0,1,0,1]. With 1 move, switching students 7 and 2, we get the array [0,0,1,1] which is optimal. Function Description Complete the function minMoves in the editor below. The function must return an integer denoting the minimum number of moves necessary to achieve an optimal configuration. minMoves has the following parameter(s): avg[avg[0],....avg[n-1]]: an array of binary digits Constraints 1 n 105 avg[i] = {0,1}) Input Format for Custom Testing Sample Case 0 Sample Input 0 8 1 1 1 1 0 0 0 0 Sample Output 0 0 Theofanstancing in a single chat sumbered inquantally from Cach can also has a biray diged with them when didate the start a performance above rage and incheaders parformance veriga The Forma de a-4 students evangad sa eng-15 Wet From guders 7 and 2 w got the ony 501 W Facts Complete the thron Elevacia the who below. The Band is wakas on kancer desting the minimum weber of restriosay to achieve an optym co viu uson Cursus * Taman og 10% Sample Case O Simple beadweep Explanation The ly ewwand base in with the cadendi keskly in front of or behind the Euch time a pair of scients ou near of moet dito sa pinulong

Step by Step Solution

3.51 Rating (161 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To solve the problem of determining the minimum number of swaps required to group all 0s to one side ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!