You are viewing a single comment's thread. Return to all comments →
Here is my O(N) c++ solution, you can watch the explanation here : https://youtu.be/L2fkDuGrxiI
int birthday(vector<int> s, int d, int m) { if(s.size() < m) return 0; int su = accumulate(s.begin(), s.begin() + m, 0), result = 0; if(su == d) result++; for(int i = m; i < s.size(); i++){ su += s[i]; su -= s[i-m]; if(su == d) result++; } return result; }
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 →
Here is my O(N) c++ solution, you can watch the explanation here : https://youtu.be/L2fkDuGrxiI