Hand of Straights LeetCode solution in C++
1class Solution {2public:3bool isNStraightHand(vector<int> &hand, int groupSize) {4int n = hand.size();5if (n % groupSize != 0) // We can't rearrange elements of size groupsize so return false6return false;7map<int, int> mp;8for (auto it : hand) mp[it]++;9while (mp.size() > 0) {10int start = mp.begin()->first; // Taking the topmost element of map1112for (int i = 0; i < groupSize; i++) {13if (mp.find(start) != mp.end()) {14mp[start]--;15if (mp[start] == 0) mp.erase(start);16start++; // Increasing for finding next consecutive element of start.17} else18return false;19}20}21return true;22}23};