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.
I didn't keep the array sorted, but I kept on checking the inputs as they came in to see if there was a match, then I just ignored the rest.
int t = 0;
cin >> t;
for(int i = 0; i < t; ++i){
int m = 0, n =0;
cin >> m;
cin >> n;
std::map<int,int> s;
bool ignore = false;
for(int j = 0; j < n; ++j){
int temp = 0;
cin >> temp;
if(!ignore){
if(temp < m){
if(s.find(m -temp)!=s.end()){
// if we find, let's print the indices, just ignore the rest of the input.
// might make it more efficient. just a thought.
cout << s[m-temp]+1 << " " << j+1 << endl;
ignore = true;
}
else{
s[temp]=j;
}
}
}
}
}
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 →
I didn't keep the array sorted, but I kept on checking the inputs as they came in to see if there was a match, then I just ignored the rest.