Question: my solution but not completely right. plz fix it There are a number of students standing in a single-file line. Each student is numbered sequentially

 my solution but not completely right. plz fix it There are

my solution but not completely right. plz fix it

a number of students standing in a single-file line. Each student is

There are a number of students standing in a single-file line. Each student is numbered sequentially from 0. Each student also has a binary digit associated with them, where O 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 1 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. min Moves has the following parameter(s): avgavg[0],... avg[n-1]]: an array of binary digits Constraints 1sns 105 avg[i] {0,1} int minMoves (vector avg) { int n; int student = n; for (int i=n-1; i>= 0; i--), if (avg[i] == student) student--; return student; int main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!