You are viewing a single comment's thread. Return to all comments →
c++, with debug. iMid - it is where the diff is equal to 1, but still goes on:
int pickingNumbers(vector<int> a) { sort(a.begin(), a.end()); int lMax = 1, l = 1, iMin = 0, iMid = 0; for (int i = 1; i < a.size(); ++i) { cout << "i " << i << endl; const int diff = a[i] - a[iMin]; cout << "diff " << diff << endl; if (diff <= 1) { if (iMid == iMin && diff == 1) { iMid = i; } l = i - iMin + 1; if (l > lMax) { lMax = l; } } else { l = 1; iMin = iMid > iMin ? iMid : i; iMid = i; } cout << "iMin " << iMin << endl; cout << "iMid " << iMid << endl; cout << "l " << l << endl; } return lMax; }
Seems like cookies are disabled on this browser, please enable them to open this website
Picking Numbers
You are viewing a single comment's thread. Return to all comments →
c++, with debug. iMid - it is where the diff is equal to 1, but still goes on: