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.
voidcountApplesAndOranges(ints,intt,inta,intb,vector<int>apples,vector<int>oranges){// get the coordinates of the fallen fruits and check whether they are in [s, t]std::transform(apples.begin(),apples.end(),apples.begin(),[a,s,t](intd){return(a+d>=s&&a+d<=t)?1:0;});std::transform(oranges.begin(),oranges.end(),oranges.begin(),[b,s,t](intd){return(b+d>=s&&b+d<=t)?1:0;});// then just sum up the elements and print the resultstd::cout<<std::accumulate(apples.begin(),apples.end(),0)<<std::endl;std::cout<<std::accumulate(oranges.begin(),oranges.end(),0)<<std::endl;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Apple and Orange
You are viewing a single comment's thread. Return to all comments →