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.
Nevertheless, I still do not see how you are saving uneeded comparisons. Also, I think your solution still does uneeded additions. Check this C++ code.
std::cout
<< count_fruits(apples, s - a, t - a)
<< std::endl
<< count_fruits(oranges, s - b, t - b);
Where the function count_fruits is like this:
int
count_fruits (vector<int>& fruits, int s, int t)
{
return std::accumulate(
fruits.begin(), fruits.end(), 0,
[&] (int v, int f)
{
return v + (s <= f && f <= t ? 1 : 0);
});
};
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 →
Oh I see. Sorry about that.
Nevertheless, I still do not see how you are saving uneeded comparisons. Also, I think your solution still does uneeded additions. Check this C++ code.
Where the function count_fruits is like this: