Two pointer approach

what is wrong with following code:

@sk1, what problem are you having with this code

it is giving wrong answer

the problem in your code is that you are printing a[i] and a[j] after incrementing i and decrementing j which should 'nt be the case

instead of

if(currentsum == k){
     i++;
     j--;
     cout<<a[i]<<" "<<a[j]<<endl;
 }

it should be

 if(currentsum == k){
     cout<<a[i]<<" "<<a[j]<<endl;
     i++;
     j--;
  }