• + 0 comments

    solution Java.

    public static int pickingNumbers(List<Integer> a) {
        // Write your code here
            Collections.sort(a);
            int l = 0;
            int r = 1;
            int score = 0;
            
            while( l<r && r < a.size() ){
                if (a.get(r) - a.get(l) <= 1){
                    score = Math.max(score , r - l + 1);
                }else{
                    l = r;
                }
                r++;
            }
            
            return score;
            
        }