Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

Algorithm for printing maximum no of pairs
Difference between en2 and en3, changed 45 character(s)
The problem statement:↵

There is an array given of 1s and -1s and there is a distance K,the output required is the maximum no of pairs such that their sum is 0 and both the numbers are within K distance.↵

eg:↵
for array:↵

1 -1 1 -1 and K = 1 answer:2↵

This can be done with brute force,but i think there would a more efficient algorithm than just brute force.Can anyone please suggest something better
 than,a pseudo code or is there any known algorithm for this?↵

Edit:A number can be taken only once.↵

Thanks.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English ss_96 2017-09-23 18:01:48 45
en2 English ss_96 2017-09-23 17:58:58 41 Tiny change: ' this?\n\nThanks' -> ' this?\n\nEdit:A number can be taken only once.\n\nThanks'
en1 English ss_96 2017-09-23 17:27:37 473 Initial revision (published)