What is problem with my code
#include
#include
using namespace std;
int main() {
int arr[1000],n,t,i,j;
cin>>n;
for(i=0;i<n;i++)
cin>>arr[i];
cin>>t;
sort(arr,arr+n);
i=0;//left pointer
j=n-1;//right pointer
while(!(i>j))
{
if((arr[i]+arr[j])==t){
cout<<arr[i]<<" and "<<arr[j]<<endl;
i++;
jā;
}
if((arr[i]+arr[j])>t)
{
jā;
}
}
return 0;
}
In targer sum pair problem, one test case is showing wrong answer and another showing time limit exceeds
@vishaaltiwari1999 First mistake is that, the 2nd if must be an else if. Correct that. Also you are missing one case: else if(arr[i]+arr[j])<t) i++
Dry run your code and check your mistakes. If still your code does not work then save your code on ide.codingblocks.com and share its link.
still one case got wrong answer