Fast Fourier Transform, Algorithms, Pattern Matching, Convolution, Combination Sum.
is the size of P and Q. Assuming that the maximum value of any element in P and Q combined is M. Then the maximum value of the sum p+q is 2M. Thus, the different sums are in the range 0 to 2M. We can create a hash table of counts of elements in array Q and then looping over P, for each sum S, find