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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Greedy
  4. Priyanka and Toys
  5. Discussions

Priyanka and Toys

Problem
Submissions
Leaderboard
Discussions
Editorial

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

  • mostafa_ragheb_1
    3 months ago+ 0 comments

    cpp

    int toys(vector<int> w) {
    sort(w.begin(),w.end());
    int counter=0;
    for(int i=0;i<w.size();i++){
        int temp=w[i];
        if(i<w.size()){
                while(temp+4>=w[i]){ 
                    i++;
                }
    
        }
        i--;
        counter++;
    }
    

    return counter; }

    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy