Sort by

recency

|

2543 Discussions

|

  • + 0 comments
    int pickingNumbers(vector<int> a) {
        sort(a.begin(), a.end());
        int c = 0;
        int i = a[0];
        int l = 0;
        for (auto n : a) {
            if (n - i > 1) {
                l = max(c, l);
                c = 1;
                i = n;
            } else {
                c++;
            }
        }
        return max(l, c);
    }
    
  • + 0 comments

    i need explanation int pickingNumbers(vector a) { map mp; for(int e : a) mp[e]++; int ans = mp[0]; for(int i = 1; i < 99; i++){ int curr = max(mp[i] + mp[i+1], mp[i] + mp[i-1]); ans = max(ans, curr); } return ans; If you're ever in need of emergency roofing services, it's important to act quickly to prevent further damage and ensure safety.

                                                     If you're ever in need of emergency roofing services, it's important to act quickly to prevent further damage and ensure safety.
    

    }

  • + 0 comments

    Here is my O(n) c++ solution, you can find the explanation here : https://youtu.be/0zvqEO1gDRw

    int pickingNumbers(vector<int> a) {
        map<int, int> mp;
        for(int e : a) mp[e]++;
        int ans = mp[0];
        for(int i = 1; i < 99; i++){
            int curr = max(mp[i] + mp[i+1], mp[i] + mp[i-1]);
            ans = max(ans, curr);
        }
        return ans;
    }
    
  • + 0 comments

    test number 7 has an errror, it must be 49, not 50

  • + 0 comments

    The "Picking Numbers" problem is a popular exercise in programming and mathematics, often requiring the selection of the largest subset of integers from an array where the absolute difference between any two numbers is no greater than one. This problem challenges individuals to think critically about grouping and organizing data while adhering to specific constraints. A common solution involves sorting the array and iterating through it to evaluate potential subsets. This process encourages efficient problem-solving techniques, such as using frequency counts or sliding window methods, making it a valuable practice Social Dental NOW for improving algorithmic thinking and optimizing performance in computational tasks.