A + B + C + D = K

Revision en1, by shivam565, 2021-10-29 11:01:43

We are given an array of n elements and I want to count the total no of such four variables with a sum equal to K, I tried it using multi-map where I store all key-value key(sum of pairs) and value(pair{i,j}) and then two-pointer, I am confused in the case when the sum of two pairs is equal to K, then where I will go (right to I, or left to j) cause If I move in both direction the time complexity will increase, and there are overlapping cases too if I store the frequency of each pair sum.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English shivam565 2021-10-29 11:01:43 510 Initial revision (published)