Picking Numbers

  • + 0 comments

    C++ Solution: int pickingNumbers(vector a) {

    sort(a.begin(), a.end());
    
    int start = 0;
    int stop = 1;
    int res = 0;
    
    while(stop < a.size()) 
    {
        if(abs(a[start] - a[stop]) <= 1)
        {
            stop++;
        }
        else
        {
            res = max(res, stop - start);
            start = stop;
            stop++;
        }
    }
    
    res = max(res, stop - start);
    
    return res;
    

    }