You are viewing a single comment's thread. Return to all comments →
int birthday(vector<int> s, int d, int m) { std::vector<int>::iterator left = s.begin(); std::vector<int>::iterator right = left + m; // points behind sliding window int sum = std::accumulate(left, right, 0); int numWays = sum == d ? 1 : 0; while (right != s.end()) { sum = sum - *left + *right; // update sum left++; right++; // and move the sliding window if (sum == d) numWays++; } return numWays; }
Seems like cookies are disabled on this browser, please enable them to open this website
Subarray Division
You are viewing a single comment's thread. Return to all comments →