I am not an algorithm person, so pardon the naivety of the question.
I have a list A containing elements 100K elements. I have another list B containing 100K elements. Let's say a is an element from list A, b is the element from list B. I want to find out those (a, b) combinations whose sum is less than 100.
One obvious way to do this is following:
results = []
for a in A:
for b in B:
if (a+b) < 100:
results.append((a,b))
but the time complexity of this approach is O(n*m) = 100K * 100K which is quite large. Is there any fast algorithm which can compute the desired output more efficiently - in terms of memory and time. If yes, can it be implemented in python?