You are viewing a single comment's thread. Return to all comments →
Using hashmap; int equalStacks(vector h1, vector h2, vector h3) { unordered_mapmp; int sum=0; for(int i=h1.size()-1;i>=0;i--){ sum+=h1[i]; mp[sum]++; } sum=0; for(int i=h2.size()-1;i>=0;i--){ sum+=h2[i]; mp[sum]++; } sum=0; for(int i=h3.size()-1;i>=0;i--){ sum+=h3[i]; mp[sum]++; } int maxi=0; for(auto itr : mp){ int a=itr.second; if(a==3 && itr.first>maxi){ maxi=itr.first; } } return maxi; }
Seems like cookies are disabled on this browser, please enable them to open this website
Equal Stacks
You are viewing a single comment's thread. Return to all comments →
Using hashmap; int equalStacks(vector h1, vector h2, vector h3) { unordered_mapmp; int sum=0; for(int i=h1.size()-1;i>=0;i--){ sum+=h1[i]; mp[sum]++; } sum=0; for(int i=h2.size()-1;i>=0;i--){ sum+=h2[i]; mp[sum]++; } sum=0; for(int i=h3.size()-1;i>=0;i--){ sum+=h3[i]; mp[sum]++; } int maxi=0; for(auto itr : mp){ int a=itr.second; if(a==3 && itr.first>maxi){ maxi=itr.first; } } return maxi; }