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.
voidwhatFlavors(vector<int>cost,intmoney){map<int,int>hash;for(inti=0;i<cost.size();i++){intremaining_money=money-cost[i];if(remaining_money<=0)continue;// cant buy a second flavor so continuesif(hash[remaining_money]>0)//if it exists{cout<<hash[remaining_money]<<" "<<i+1<<endl;return;}hash[cost[i]]=i+1;}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
C++ Solution