25. Maximum Sum Combination
My Approach
Explain with Example
Suppose:
- A = [3, 2, 4]
- B = [2, 3, 1]
- K = 3
- Sorted A = [2, 3, 4]
- Sorted B = [1, 2, 3]
1. Initially, st = [{7, 2, 2}] (sum of last elements from A and B).
2. After the first iteration, out = [7], st = [{6, 2, 1}, {6, 1, 2}].
3. After the second iteration, out = [7, 6], st = [{6, 1, 2}, {5,2,0}, {5,1,1}].
4. After the third iteration, out = [7, 6, 6], st = [{5,2,0}, {5,1,1}, {5,0,2}].
So, the result is [7, 6, 6].Time and Auxiliary Space Complexity
Code (C++)
Contribution and Support
Last updated