Math, asked by Titli6545, 1 year ago

Given two positive integer arrays arr1 and arr2 of lengths len1 and len2

Answers

Answered by AnmolRaii
0

Example:

[1,2,4,5] output would be [1,5] and [2,4]

So here is what I tried but code breaks at one point need help with decision making at that point.From below code if(avgArr1 < avgArr2){ is the point where I decide which needs to be the source array which needs to be destination array for inserting and deleting elements. This condition is not reliable and empties one of the array.

This problem might be solved with dynamic programming. Make a table with size OverallSum. Fill it with all possible subsets sums, recording also number of items and the last item used to make every sum.

Let average of whole array is A = P/Q(rational value, GCD(P,Q)=1). Now check whether sums P, 2P, 3P... kP might be created from Q, 2Q, 3Q...kQ items. If yes, unwind sum to get items composing this sum

For example [1, 2, 5, 6] A = 3.5 = 7/2 so check if sum 7 might be composed from two items

Similar questions