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...
-
In a study of the rotational spectrum of the linear Fe CO radical, K. Tanaka, M. Shirasaka, and T. Tanaka (J. Chem. Phys. 106,6820 (1997)) report the following J+ I (,- J transitions: J 24 25 26 27...
-
Design an emitter-stabilized network at ICQ = ICsat and VCEQ = 1/2 VCC = Use VCC = 20 V, ICsat = 10 mA, = 120, and RC = 4RE. Use standard values.
-
Repeat Problem 10.27 if the Froude number is 2.75. Problem 10.27 Water flows in the river shown in Fig. P10.27 with a uniform bottom slope. The total head at each section is measured by using Pitot...
-
You have a friend, Icahn Betitall, who just started a small business. He is paying a hefty premium for insurance. Icahns insurance agent told him that he is insuring against the risk of loss on fire,...
-
With many companies merging in different countries, are cultures merging too? Why is that important to IHR? Why is human resources in the health care industry just as important as any other industry?
-
The fish department of the local grocery store faces unique problems. Fish is extremely perishable and can only be sold on the day it arrives in the store. Fish is delivered at 3 am and can be sold...
-
1. A steam power plant with two boilers are connected to a steam turbine. Both boiler received a H20 at 5MPa and 190C. Both hot vapors will enter a mixing chamber before entering the turbine. Steam...
-
Salesforce recently acquired Slack, is this an example of an LBM or RMB? Explain. How does it meet the criteria for an LBM/RBM? Do you think this was a good move for Salesforce?
-
Current Attempt in Progress On January 1, 2023, Sunland Corp. sold property to Marvin Ltd., for which Sunland had originally paid $570,000. There was no established exchange price for this property....
-
A steam fitter earns $19.40 per hour plus time and a half for overtime (more than 40 hours in one week ). If she works 56(1)/(2) hours one week, what is her gross pay for that week?
-
Paual, the HR director, was pleased to have just hired someone she felt was highly qualified as the benefits director. Charlie was bright, graduated from U. of Chicago and then traveled to England as...
-
Consider a hypothetical Control Unit which supports 8 k words. The Hardware contains 64 internal control signals, 16 bus control signals, 8 Flags and 8 branch conditions. What is the size of control...
-
Write a shell script to generate mark sheet of a student. Take 3 subjects, calculate and display total marks, percentage and Class obtained by the student.
-
Willingness to pay as a measure of a person's value for a particular good measures the maximum a person would be willing to pay requires that payment actually be made depends on the satisfaction that...
-
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...
-
If so, is it similar to one of the three formats illustrated in this chapter? If not, how is it different?
-
Do you know about the chart of accounts in your organization as it pertains to information you receive?
-
If so, did you receive the information in a formal seminar or in an informal manner, oneon-one with another individual? Do you think this was the best way? Why?
Study smarter with the SolutionInn App