We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

I had a lot of confusion and had to read the discussions for it to click that the entire subset had to be within 0-1 integers from one another. I feel like the problem is worded poorly, or ambiguously at best. I was under the assumption initially that the next integer in the set had to be the same, one more, or one less than the previous.

Anyway, my working Java Code:

publicstaticintpickingNumbers(List<Integer>a){// Write your code hereintlongestSubArrayLength=0;Collections.sort(a);for(inti=0;i<a.size()-1;i++){intcomparator=a.get(i);List<Integer>subArray=newArrayList<Integer>();subArray.add(comparator);for(intj=i+1;j<a.size();j++){intrange=Math.abs(comparator-a.get(j));if(range==0||range==1)subArray.add(a.get(j));elsebreak;}if(subArray.size()>longestSubArrayLength)longestSubArrayLength=subArray.size();}returnlongestSubArrayLength;}

## Picking Numbers

You are viewing a single comment's thread. Return to all comments →

I had a lot of confusion and had to read the discussions for it to click that the entire subset had to be within 0-1 integers from one another. I feel like the problem is worded poorly, or ambiguously at best. I was under the assumption initially that the next integer in the set had to be the same, one more, or one less than the previous.

Anyway, my working Java Code: