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...
-
Write the structure of the DNA dinucleotide T-A in which T has a free 59-hydroxyl group and A has a free 39-hydroxyl group.
-
Summaries of selected data for three companies follow. Th ree items are missing from each summary. Instructions Determine the missing amounts. Midway Company Wheel Company Ferris Company Beginning of...
-
What is the maximum price an investor will pay for a bond with a face value of $\$ 5,000$ and a coupon rate of $12 \%$, paid annually? Assume the investor seeks a yield of $10 \%$ and the bond will...
-
Townsend Industries Inc. manufactures recreational vehicles. Townsend uses a job order cost system. The time tickets from November jobs are summarized as follows: Job...
-
What could the strategies be for these categories? ugh your research, which will inform your strategic analysis of their importance to the firm's efforts to market and compete within your target...
-
Jamie Lee Jackson, age 26, is in her last semester of college and is anxiously waiting for graduation day that is just around the corner! She still works part-time as a bakery clerk, has been...
-
A positively charged metal sphere A is brought into contact with an uncharged metal sphere B . As a result: Group of answer choices a. both spheres are positively charged b. A is positively charged...
-
What can you infer as the cause-and-effect relationship here? Beef Price (per pound) $2.70 $2.60 $2.50 $2.40 $2.30 $2.20 $2.10 $2.00 $2.09 $ 1.89 $ 1.99 2,500 3,500 $ 2.39 $ 2.69 1,000 4,000 6,000...
-
Discuss how you as a visionary school leader would address on-going challenges and how you would apply current best practice in collaborating with parents, teachers, and the community.
-
BCG Matrix on Domino's Pizza for the 2023 year. I want to know how to use these three divisions which are Domino's owned domestic stores, the domestic supply chain, and the franchise owned stores...
-
Find an example of collusion between firms (not discussed in class) and explain what happened. Provide the link. (2 extra points if no one else chooses the same example as you...to encourage you to...
-
36. Calculating the Cost of Jobs and Making Journal Entries for a Service Company. Sampson & Associates provides accounting services. It began jobs 1 through 3 in the first week of January. The...
-
Dome Metals has credit sales of $324,000 yearly. If Dome offers a 3 percent discount for payment in 15 days, what will the average accounts receivable balance be? Assume all customers would pay on...
-
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.
-
Among your colleagues in class, identify a term or phrase italicized in this chapter that you think is the most significant from your reading. Absent team consensus, then just provide your...
-
What are the two key financial objectives in the management of a company? How can a focus on these objectives create ethical dilemmas?
-
What is the purpose of financial statements? Would you want to produce them even if they were not required, say, for entity tax reporting?
Study smarter with the SolutionInn App