Posted on

Description

Submission

class Solution {
public:
    bool canArrange(vector<int>& arr, int k) {
        vector<int> remainder(k, 0); // remainder count
        for(auto x: arr) {
            while(x < 0) x += (-x / k + 1) * k;
            remainder[x % k]++;
        }
        
        for(int i = 1; i <= k/2; ++i) {
            if(i == k - i && remainder[i] % 2 != 0) return false;
            if(remainder[i] != remainder[k-i]) return false; 
        }
        
        return true;
    }
};

Leave a Reply

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