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 have this solution but getting Timeout, not sure why? Any Help?
intboardCutting(vector<int>cost_y,vector<int>cost_x){intx=1;inty=1;longM=pow(10,9)+7;sort(cost_x.begin(),cost_x.end(),greater<int>());sort(cost_y.begin(),cost_y.end(),greater<int>());inti=0;intj=0;intresult=0;while(i<cost_x.size()||j<cost_y.size()){intcx=i<cost_x.size()?cost_x[i]:0;intcy=j<cost_y.size()?cost_y[j]:0;// if both equal take from the largest arrayif(cx==cy){if(cost_x.size()-i>cost_y.size()-j){cy=0;}else{cx=0;}}if(cx>cy){result+=cx*x;y+=1;++i;}else{result+=cy*y;x+=1;++j;}result=result%M;}returnresult;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Cutting Boards
You are viewing a single comment's thread. Return to all comments →
I have this solution but getting Timeout, not sure why? Any Help?