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.
intpylons(intk,vector<int>arr){intresult=0;// start from the beginning and find the furthest city to build the plantinti=0;while(i<arr.size()){// cout << i << endl;// do backward search from the furthest possible to currentboolfound=false;for(intj=i+k-1;(j>=i-k+1)&&(j>=0);j--){// cout << " " << j << endl;if(j<arr.size()){if(arr[j]==1){// cout << " = " << j << endl;// put plant here and result++;// calculate the new beginningi=j+k;found=true;break;}}}if(!found)return-1;}returnresult;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Goodland Electricity
You are viewing a single comment's thread. Return to all comments →
c++