1. Array Subsets Given an integer array, divide the array into 2 subsets A and B...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Array Subsets Given an integer array, divide the array into 2 subsets A and B while respecting the following conditions: The intersection of A and B is null. • The union A and B is equal to the original array. • The number of elements in subset A is minimal. . • The sum of A's elements is greater than the sum of B's elements. Return the subset A in increasing order where the sum of A's elements is greater than the sum of B's elements. If more than one subset exists, return the one with the maximal sum. Example n=5 arr = [3, 7, 5, 6, 2] The 2 subsets in arr that satisfy the conditions for A are [5, 7] and [6, 7]: A is minimal (size 2) • Sum(A) = (5 + 7) = 12 > Sum(B) = (2+ 3 + 6) = 11 • Sum(A) = (6 + 7) = 13 > Sum(B) = (2+ 3+5) = 10 • The intersection of A and B is null and their union is equal to arr. The subset A where the sum of its elements is maximal is [6, 7]. Function Description Complete the subsetA function in the editor below. subsetA has the following parameter(s): int arr[]: an integer array Returns: int[]: an integer array with the values of subset A. Constraints • 1≤n≤105 • 1 ≤ arr[i] ≤ 105 (where 0<i<n) 1. Array Subsets Given an integer array, divide the array into 2 subsets A and B while respecting the following conditions: The intersection of A and B is null. • The union A and B is equal to the original array. • The number of elements in subset A is minimal. . • The sum of A's elements is greater than the sum of B's elements. Return the subset A in increasing order where the sum of A's elements is greater than the sum of B's elements. If more than one subset exists, return the one with the maximal sum. Example n=5 arr = [3, 7, 5, 6, 2] The 2 subsets in arr that satisfy the conditions for A are [5, 7] and [6, 7]: A is minimal (size 2) • Sum(A) = (5 + 7) = 12 > Sum(B) = (2+ 3 + 6) = 11 • Sum(A) = (6 + 7) = 13 > Sum(B) = (2+ 3+5) = 10 • The intersection of A and B is null and their union is equal to arr. The subset A where the sum of its elements is maximal is [6, 7]. Function Description Complete the subsetA function in the editor below. subsetA has the following parameter(s): int arr[]: an integer array Returns: int[]: an integer array with the values of subset A. Constraints • 1≤n≤105 • 1 ≤ arr[i] ≤ 105 (where 0<i<n)
Expert Answer:
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
Management of the firm recruits from what major external environmental factor?
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
FIGURE Q38.5 is the current-versus-potential-difference graph for a photoelectric-effect experiment with an unknown metal. If classical physics provided the correct description of the photoelectric...
-
Did Einstein support quantum mechanics as being fundamental physics, or did he think quantum mechanics was incomplete?
-
Build the Simulink model shown in Figure 1.27. The Step signal has a step time of 1 and a final value of 1 ; that is, it assumes a value of 1 immediately after \(t=1\) and a value of 0 otherwise. The...
-
Which of the following numbers are in scientific notation? If the number is not in scientific notation, explain why it is not. 1. \(-9.67 \times 10^{20}\) 2. \(145 \times 10^{-8}\) 3. 1.45
-
Rosenthal Company manufactures bowling balls through two processes: Molding and Packaging. In the Molding Department, the urethane, rubber, plastics, and other materials are molded into bowling...
-
You have been hired by an inventor of a new power cell for cars,trucks and boats, who has some inquiries from prospective investorswho would like to know more about the invention before they putthe 2...
-
Alice J. and Bruce M. Byrd are married taxpayers who file a joint return. Their Social Security numbers are 123-45-6789 and 111-11-1111, respectively. Alice's birthday is September 21, 1966, and...
-
can you write me 1500 on the loyalty program, Devotion ProgramIssues and recommendations for the company Nestle? 1 answer
-
Prof provided the answer key but REQUIRES showing the solution/analysis using Excel functions/formulas STEP-BY-STEP. Thank you. Answer Key : PJ% = .2974, or 29.74% PK% = .2333, or 23.33% Question :...
-
Alex pushes against a car stuck in a snowbank with a force of 8 5 lbf , while his friend sits nervously behind the steering wheel trying not to make the tires spin. They try this for 1 0 minutes....
-
heat up two slices of pizza in the oven. Each slice has a mass of 1 0 0 g . The pizza ( cheese ) is initially solid at a temperature of 3 9 . 2 F . I place the pizza slices in a 3 5 0 F preheated...
-
Our goal is to observe some of the best programs and to recognize what made these programs superior. Select one campaign that you consider outstanding. State the slogan (or if no slogan state in a...
-
XYZ firm reported net income of $3.44bn and revenues of $19.1bn over the most recent twelve-month period. The current market capitalization for XYZ firm is $3.8bn. What is XYZ firm's P/S ratio
-
The Great Divide results from 5 barriers that make functional integration difficult. Please define / summarize these barriers, and discuss your experience with each in your professional or personal...
-
Explain why it is not wise to accept a null hypothesis.
-
Suppose we have stored n keys in a hash table of size m, with collisions resolved by chaining, and that we know the length of each chain, including the length L of the longest chain. Describe a...
-
Professor Stewart is consulting for the president of a corporation that is planning a company party. The company has a hierarchical structure, that is, the supervisor relation forms a tree rooted at...
-
Given a list of values z 0 , z 1 , . . . ,z n - 1 (possibly with repetitions), show how to find the coefficients of a polynomial P(x) of degree-bound n + 1 that has zeros only at z 0 , z 1 , . . . ,z...
-
For each of the flows in Problems 1 and 2, for which an irregular structured grid has been found necessary and possible, suggest a coordinate transformation.
-
Consider the primitive LES and RANS models, in which the eddy viscosity formulas (11.32) and (11.77) are applied with constant eddy viscosity \(\mu_{t}\). What is the drawback of these models? Should...
-
If your course involves exercises with CFD software, study the documentation to determine whether the LES option is implemented. Which closure models are used? What approach is taken to the near-wall...
Study smarter with the SolutionInn App