We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
every time when we have enter an array,we have to ckeck whether the sum of that array with each array we already entered or exist is equal to m(M dollars) .if it is then we have to print the index +1 (your one is bit similar to mine but this one is much faster)(below one is two pointer method,which is much faster)
int main()
{
int t;cin>>t;
while(t--)
{
int m,n,j;cin>>m>>n;
int a[n];
for(int i=0;i<n;i++)
{j=0;
cin>>a[i];
while(a[j]+a[i]!=m&&j<i)++j;// searching of j where a[j]+a[i]=m
if(a[i]+a[j]==m&&i>j){
cout<<j+1<<" "<<i+1<<endl;break;}
} cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
every time when we have enter an array,we have to ckeck whether the sum of that array with each array we already entered or exist is equal to m(M dollars) .if it is then we have to print the index +1 (your one is bit similar to mine but this one is much faster)(below one is two pointer method,which is much faster)
}