There are a number of students standing in a single-file line Each student is numbered sequentially...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 performhance 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 Twaps places, it counts as a move. Determine the minimum number of moves needed to create an optimal configuration For exampie, there are nad students arranged as avg=0,1,0.1. With I 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 minMoves has the following parameterts). avgjavg|0). avgin 1 an array of binary digits Constraints 1sns 10 • avg E 10, 1) Input Format for Custom Testing Impur trom samw procesea as follows and passed to the function. The first line contains an integer n, the size of the array avg. Each of the next n lineh contains a birary digit as an integer, avg Sample Case O Explanation 0 There is only one pair of above and below average students standing next to each other. This cannot be reduced, so no moves are necessary. Sample Case 1 Sample Input 11110101 Sample Output 1 Explanation 1 We can perform the following minimal sequence of 3 moves 1 1110IO1-11111001-111116 contiguration 111110 e to achieve an optimal Sample Case 2 Sample Impurz 101000e1 Sample Output 2 Explanation 2 We can perform the following minimal sequence of 6 moves 10iee001-11eee e e1-11eee010-110ee1 ee-11ee10 00-1 L e e to achieve an optimal configuration 1 * import java.1o.; 12 13 14 1S class Result ( 16 17 H 18 * Complete the mintoves function below. 19 * The function is expected to return an INTEGER. * The function accepts INTEGER ARRAY avg as parameter, 20 21 22 23 publie static int minMoves(List<Integer> avg) ( / weite your code here 24E 25 26 27 28 29 30 31 public class Solution ( 58 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 performhance 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 Twaps places, it counts as a move. Determine the minimum number of moves needed to create an optimal configuration For exampie, there are nad students arranged as avg=0,1,0.1. With I 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 minMoves has the following parameterts). avgjavg|0). avgin 1 an array of binary digits Constraints 1sns 10 • avg E 10, 1) Input Format for Custom Testing Impur trom samw procesea as follows and passed to the function. The first line contains an integer n, the size of the array avg. Each of the next n lineh contains a birary digit as an integer, avg Sample Case O Explanation 0 There is only one pair of above and below average students standing next to each other. This cannot be reduced, so no moves are necessary. Sample Case 1 Sample Input 11110101 Sample Output 1 Explanation 1 We can perform the following minimal sequence of 3 moves 1 1110IO1-11111001-111116 contiguration 111110 e to achieve an optimal Sample Case 2 Sample Impurz 101000e1 Sample Output 2 Explanation 2 We can perform the following minimal sequence of 6 moves 10iee001-11eee e e1-11eee010-110ee1 ee-11ee10 00-1 L e e to achieve an optimal configuration 1 * import java.1o.; 12 13 14 1S class Result ( 16 17 H 18 * Complete the mintoves function below. 19 * The function is expected to return an INTEGER. * The function accepts INTEGER ARRAY avg as parameter, 20 21 22 23 publie static int minMoves(List<Integer> avg) ( / weite your code here 24E 25 26 27 28 29 30 31 public class Solution ( 58
Expert Answer:
Answer rating: 100% (QA)
LOGIC To make sure that number of adjacent pairs of students where one student is a 0 and the other ... View the full answer
Related Book For
Posted Date:
Students also viewed these mathematics questions
-
The mean ratio of students per teacher in U.S. public schools was 15.1 students per teacher in 2013, down 5.6% from 2000. What was the mean ratio of students per teacher in 2000?
-
The national average for the number of students per teacher for all U.S. public schools is 15.9.Arandom sample of 12 school districts from a moderately populated area showed that the mean number of...
-
A teacher assigns a group of 30 students into 3 groups of 10. The way the assignment process works is as follows: the teacher first randomly picks 10 students from the class and assigns them to group...
-
What type of insurance policy insures against all risks of loss that are not specifically excluded by the policy? OA) Binder policy OB) Named peril policy OC) Specified peril policy OD) Open peril...
-
List the eight steps in the accounting cycle.
-
Evaluate *x sin t t X lim x-3 x - 33 - dt
-
Two small, irregularly shaped conducting objects, one carrying charge \(+q\) and one carrying charge \(-q\), are placed on an \(x\) axis at \(x=-4.0 \mathrm{~m}\) and \(x=+4.0 \mathrm{~m}\),...
-
On January 1, 2014, Mechanics Credit Union (MCU) issued 7%, 20-year bonds payable with face value of $ 300,000. The bonds pay interest on June 30 and December 31. Requirements 1. If the market...
-
4. The atomic numbers of elements, U, V, W and X are 13, 14, 16 and 17 respectively. Which one of the elements will react with oxygen to form an ionic compound? (Atomic number of oxygen is 8) X A. B....
-
Preparing an Individuals Tax Form. Caleb Lee graduated from college in 2018 and began work as a systems analyst in July of that year. He is preparing to file his income tax return for 2018, and has...
-
Zara Supply Chain Lean operations 1. What is lean operations and how does it work? 2. How Zara implement lean in it business? 3. What are the challenges when implementing lean? 4. Is there any...
-
7. How many molecules are there in a sample of gas that occupies a volume 9 L at STP. (1 point) A. O 2.42e23 B. O 1.08e23 C. O 1.586e23 D. O 2.165e23 E. O 4.369e23 8. A 100 g sample of di-atomic...
-
Figure 3 shows an elastic collision of two pucks on a friction-less air hockey table. Puck A has mass m = 0.500 kg and puck B has mass mg = 0.300 kg. Puck A has an initial velocity of 4.00 m/s in the...
-
A ball travels along a straight track with the acceleration a = position of the ball is s = 2ft and the velocity of the ball is v = -2- (3t-4)- When t = ft X 82 ft S ft a. What is the ball's velocity...
-
An object having emissivity 0.0867 radiates heat at 15 W, when is a temperature is T. if T is doubled what is the rate at which it radiates heat ?
-
Write the formula of the following coordination compounds: a. Pentaamminecarbonatocobalt(III) Fluoride... b. trans-diamminetetraisothiocyanatochromate(III) ion.
-
Q1. The character played by Henry Fonda was not the "official" leader of the group, i.e. he was not elected Foreman, yet he became the real leader of the group. What characteristics did he exhibit...
-
The Place-Plus real estate development firm in Problem 24 is dissatisfied with the economists estimate of the probabilities of future interest rate movement, so it is considering having a financial...
-
Se = (Yi xi)2 / n 2; y1 = 2 y2 = 7, y3 = 9, x1 = 3, x2 = 4, x3 = 11, n = 14 (standard error of the estimate)
-
Table 8 shows the top 5 cosmetic surgeries in 2013, their frequencies (in number of thousands of times performed in 2013), and their relative frequencies. a. Construct a frequency bar graph. b....
-
280,000 Write the number in scientific notation.
-
Are allocations \(a\) and \(g\) in Figure 10.4 part of the contract curve? Data From Figure 10.4:- 60 80 50 160 30 12. 20 20 Jane's wood 40 40 Denise's candy Od 20 Contract curve Denise's wood 20 218...
-
People who qualify for affordable housing in Sydney, Australia, have their rent capped at \(30 \%\) of their gross annual income. People who live in private rental properties in the city are not...
-
Governments use wage subsidies to maintain employment in times of economic recession, to encourage firms to hire and train specific groups of workers such as low-income workers, women, and students...
Study smarter with the SolutionInn App