• + 0 comments

    The fact that the hardest part on this thing was remembering how mods work other than checking if smt is divisible xd

    int nonDivisibleSubset(int k, vector<int> s) {
        vector<int> mods(k, 0);
    
        for (int x : s) {
            mods[x % k]++;
        }
    
        int count = 0;
    
        if (mods[0] > 0) count++;
    
        for (int i = 1; i <= k / 2; i++) {
            if (i == k - i) {
                count++;
            } else {
                count += max(mods[i], mods[k - i]);
            }
        }
    
        return count;
    }