You are viewing a single comment's thread. Return to all comments →
public static int pickingNumbers(List<Integer> a) { Collections.sort(a); int size = 1; int maxSize = 0; List<Integer> bag = new ArrayList<Integer>(); for(int i = 0; i < a.size(); i++) { bag.add(a.get(i)); Collections.sort(bag); for (Integer b : bag) { if (Math.abs(b - a.get(i)) > 1) { bag.remove(0); break; } else { size = bag.size(); } } maxSize = Math.max(size, maxSize); } return maxSize; }
Seems like cookies are disabled on this browser, please enable them to open this website
Picking Numbers
You are viewing a single comment's thread. Return to all comments →