You are viewing a single comment's thread. Return to all comments →
Here is my O(n) c++ solution, you can find the explanation here : https://youtu.be/0zvqEO1gDRw
int pickingNumbers(vector<int> a) { map<int, int> mp; for(int e : a) mp[e]++; int ans = mp[0]; for(int i = 1; i < 99; i++){ int curr = max(mp[i] + mp[i+1], mp[i] + mp[i-1]); ans = max(ans, curr); } return ans; }
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 →
Here is my O(n) c++ solution, you can find the explanation here : https://youtu.be/0zvqEO1gDRw