/* * Complete the 'minMoves' function below. * * The function is expected to return an INTEGER....
Fantastic news! We've Found the answer you've been seeking!
Question:
/* * 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) {
}
Transcribed Image Text:
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 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
Expert Answer:
Related Book For
Discrete Mathematics and Its Applications
ISBN: 978-0073383095
7th edition
Authors: Kenneth H. Rosen
Posted Date:
Students also viewed these programming questions
-
The stock of Koch Brickyard, Inc., is expected to return 14 percent with a standard deviation of 5 percent. Uptown Potbelly Stove Works stock is expected to return 16 percent with a standard...
-
If an investment is expected to return of 5 percent in the future, a $53,000 investment will grow to how much in 22 years?
-
If a project costs $100,000 and is expected to return $25,000 annually, how long does it take to recover the initial investment? What would be the discounted payback period at i = 15%?
-
Use f(x) and g(x) to find a formula for each expression. Identify its domain. (a) (f + g)(x) (c) (fg)(x) (b) (f- g)(x) (d) (f/g)(x)
-
Has the ease of removing your name from an e-mail list changed? A study of 100 large online retailers revealed the following: a. Set up the null and alternative hypotheses to try to determine whether...
-
SS 3.20 (SI/USCS Units) In a Brinell hardness test, a 1500-kg load is pressed into a specimen using a 10-mm-diameter hardened steel ball. The resulting indentation has a diameter = 3.2 mm. (a)...
-
Use the abbreviated comparative financial statements for West Coast Construction, Inc. in the Working Papers. Instructions: 1. Review the comparative income statement and identify the amounts of net...
-
Choose one of the five competitive forces in Porters model, and describe a new opportunity and a new threat due to e-commerce via the Internet for a specific industry of your choosing.
-
Lee and Julia are common-law partners, both aged 35. Lee's mother, aged 75, lives with them and is financially dependant on Lee. While applying for life insurance, Lee mentions that if he dies, he...
-
Instructions You are expected to read the article titled: Risk mitigation in IT outsourcing strategy revisited: longitudinal case research at LISA, and answer the case study questions in the next...
-
Question 1 10 points a) Roots of a complex number lie on the vertices of a square of arm length 22. The diagonals intersect at the origin, and make an angle with the axes. Find the complex number. b)...
-
Which of the following is not an element of an internal control system? a. Auditing b. The control environment C. Monitoring d. Information and communication
-
Find a case in California that discusses the hearsay exception. What did the court rule?
-
Which of the following is not a control activity? a. Mandatory vacations b. Risk assessment C. Security measures d. Proper authorization
-
How might a witnesss statement be impeached?
-
What is the other assumption that must be true? There are two assumptions that must be true in order to perform an F test of two variances.
-
__________ assumes oldest inventory is used up first, thus in calculations we would use the __________ purchase price to calculate the value of ending inventory
-
The registrar of a college with a population of N = 4,000 full-time students is asked by the president to conduct a survey to measure satisfaction with the quality of life on campus. The following...
-
Suppose that we vary the payoff to the winning player in the game of nim so that the payoff is n dollars when n is the number of legal moves made before a terminal position is reached. Find the...
-
Construct a finite-state automaton that recognizes the set of bit strings consisting of a 0 followed by a string with an odd number of 1s.
-
Suppose that we roll a fair die until a 6 comes up or we have rolled it 10 times. What is the expected number of times we roll the die?
-
C. Gomez, corporate engineer of Allied Products Ltd. is proposing the replacement of existing equipment with more efficient equipment. According to information received by Gomez, the proposed...
-
Match each of the following descriptions, a through \(h\), with a capital budgeting method: (1) payback method, (2) net present value, (3) profitability index, or (4) internal rate of return. More...
-
SavingsPlus Inc. is considering an investment in computer technology. The project would require an initial investment of \(\$ 240,000\) and have an expected life of six years with no salvage value....
Study smarter with the SolutionInn App