Posted on

Description

Submission

class Solution {
public:
    bool isPossibleDivide(vector<int>& nums, int k) {
        if(nums.size() % k != 0) return false;
        map<int, int> Map;

        for(int num: nums) {
            ++Map[num];
        }

        while(!Map.empty()) {
            int start = Map.begin()->first;
            for(int i = start; i < start + k; ++i) {
                auto it = Map.find(i);
                if(it == Map.end()) return false;
                --it->second;
                if(it->second == 0) Map.erase(it);
            }
        }
        
        return true;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *