Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

1. Array Subsets Given an integer array, divide the array into 2 subsets A and B while respecting the following conditions: The intersection of

1. Array Subsets Given an integer array, divide the array into 2 subsets A and B while respecting the

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 1n105 1 arr[i] 105 (where 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

More Books

Students explore these related Programming questions