Priyanka and Toys

  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/Es5l0jbSH9I

    int toys(vector<int> w) {
        sort(w.begin(), w.end());
        int result = 1, mi = w[0];
        for(int item: w){
            if(item > mi + 4){
                mi = item;
                result++;
            }
        }
        return result;
    }