Uber | SDE 2 | Onsite

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2023-01-03Added By Anonymous
Source: Link

Given N and an array of length 3*N.

You have to remove exactly N elements from this array.

From the remaining array of length 2N, assuming S1 is the sum of first N elements and S2 is the sum of remaining N elements, what is ths maximum possible value of S1 - S2 we can get.

Example:

1N = 2, A = [3,1,5,2,1,1] 2remove 2 and 1 array will become 3,5,1,1 3and ans is (3+5)-(1+1) = 6 4 5N = 2, A = [1,2,5,3,5,1] 6remove 1, 5 and array will become 2,5,3,1 7ans will be (2+5)-(3+1) = 3 8 9N = 2, A = [1,2,5,3,1,1] 10remove 1, 2 and array will become 5,3,1,1 11ans will be (5+3)-(1+1) = 6


Comments