You are viewing a single comment's thread. Return to all comments →
C# solution
public static int nonDivisibleSubset(int k, List<int> s) { int[] remainders = new int[k]; foreach (int num in s) { int remainder = num % k; remainders[remainder]++; } int count = Math.Min(remainders[0], 1); for (int i = 1; i <= k / 2; i++) { if (i != k - i) { count += Math.Max(remainders[i], remainders[k - i]); } else if (remainders[i] > 0) { count++; } } return count; }
Non-Divisible Subset
You are viewing a single comment's thread. Return to all comments →
C# solution