There are two sorted array Aand Bthe same length, which Ais sorted in ascending order, and the array Bis sorted in descending order.
A = {1, 3, 7, 7, 7, 7}
B = {7, 7, 5, 5, 5, 4}
My task is to find two elements: one of Aand the other of B, so that their sum is maximum.
There is a limitation that I can select any element from A, but I need to select an element from Bin such a way that the index of the array element is Bgreater than the index of the element selected A.
In this case, the maximum amount that can be selected is 12. I did it in O(n), just repeating from left to right.
I want to know if there is a better and more efficient way to find the sum of these two elements.
source
share