You are viewing a single comment's thread. Return to all comments →
You can move the code for calculating number of fruits on house to function to keep it DRY:
int CalculateNumberOfFruitsOnHouse(int s, int t, int tree, const std::vector<int> &fruits) { int rel_s = s - tree; int rel_t = t - tree; int num = 0; for(int fruit : fruits){ if(fruit >= rel_s && fruit <= rel_t) ++num; } return num; }
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 →
You can move the code for calculating number of fruits on house to function to keep it DRY: