Leet Code Daily 2024-06-06 - Hand of Straights
Code
class Solution {
public:
bool isNStraightHand(vector<int>& hand, int groupSize) {
unordered_map<int, int> cnt_unused;
for (const auto& val : hand) {
cnt_unused[val]++;
}
sort(hand.begin(), hand.end());
for (const auto& val : hand) {
if (cnt_unused[val] > 0) {
for (int i = val; i < val + groupSize; i++) {
if (cnt_unused[i] < 1) {
return false;
}
cnt_unused[i]--;
}
}
}
return true;
}
};