I have a 2d-array with positive integers (limited to max. of 10^6). The array has a size of 10^5x2 like this:
140173 471588 291471 516770 273559 538464 125329 159490 5034 59284 438681 467752 578846 ...
80182 120937 410438 338171 169200 123061 175433 159358 462440 260476 179648 395141 508690 ...
Now, I need to find the biggest pair of values from the Array, with pairs formed by using one Value of the top row and one from the bottom row. I have a working python example, but it is really slow (attached below). How can I make this faster, or even better, is there a better way?
def solve(n, a, b):
gD = int(0)
for i in range(n):
for j in range(n):
d = (a[i] + b[j])
if d > gD: gD = d
return gD
n is the length of the two arrays, they're of equal length.
I loop over every possible value, and if it is bigger than the prev. biggest pair, I save it in gD