I used the same solution, but in my first attempt it gave me WA, but on 2nd attempt solution got accepted?
I used the same solution, but in my first attempt it gave me WA, but on 2nd attempt solution got accepted?
Could you please share your submissions?
#include<bits/stdc++.h> using namespace std; void pair_sum(int arr[], int n, int k){ int i=0; int j=n-1; while(i<j){ int sum=arr[i] + arr[j]; if(sum<k){ i++; } else if(sum<k){ j–; }else{ cout<<arr[i]<<" and "<<arr[j]<<endl; i++; j–; } } } int main() { int n; cin>>n; int arr[1000]; for(int i=0;i<n;i++){ cin>>arr[i]; } int k; cin>>k; sort(arr, arr+n); pair_sum(arr, n, k); return 0; }
@amandeepdogra65 i saw your submissions, they are not the same code. Can you please both the codes you are saying that are same and gave different scores?
Please share the codes using CB IDE
In one code I did sorting in main() and in other I did sorting in the function itself.
@amandeepdogra65 you used the same condition twice here (sum < k) but you changed this in the other code.

Ohh…that’s a typo. Thanks. I didn’t see that!