Given two sets of "n" numbers A and B. Choose one element from A and one from B so that the sum is equal to the given value of "val".
I have a solution like:
We can hash elements Set A and Set B and check for each element in the set A whether val-arr [i] exists in the Set B hash or not. It takes O (n) and O (n) time. Could there be better solutions with space like O (1) and O (n) time?
source share