You are viewing a single comment's thread. Return to all comments →
public static int nonDivisibleSubset(int k, List<Integer> s) { int maximalSubsetSize = 0; int[] countArray = new int[k]; for (int i = 0; i < s.size(); i++) { int number = s.get(i); countArray[number % k]++; } for (int i = 0; i < countArray.length; i++) { int p = i; int q = k - p; if (q < p) { break; } if (p == 0 || p == q) { maximalSubsetSize = maximalSubsetSize + Math.min(countArray[p], 1); } else { maximalSubsetSize = maximalSubsetSize + Math.max(countArray[p], countArray[q]); } } return maximalSubsetSize; }
Seems like cookies are disabled on this browser, please enable them to open this website
Non-Divisible Subset
You are viewing a single comment's thread. Return to all comments →