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
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Greedy
  4. Jim and the Orders
  5. Discussions

Jim and the Orders

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 454 Discussions, By:

votes

Please Login in order to post a comment

  • somananda
    7 years ago+ 9 comments

    for those who got problem (simple method using multimap)

    int main() {

        multimap<int,int> m;
        int n;cin>>n;
        for(int i=1;i<=n;i++)
        {
        int a,b; cin>>a>>b;
        m.insert(make_pair(a+b,i));
        }   
    
       for(multimap<int,int >::iterator me=m.begin();me!=m.end();me++ )
        {cout<<me->second<<" ";
                }        
    return 0;
    

    }

    52|
    Permalink
    View more Comments..
  • saurabhiitr
    7 years ago+ 10 comments

    getting same output as defined in test case 7 on my local pc it fails in hacker rank kindly help....

    31|
    Permalink
    View more Comments..
  • vusirikala
    7 years ago+ 1 comment

    How does this problem come under "greedy" paradigm?

    10|
    Permalink
  • patrick_garvey
    4 years ago+ 2 comments

    def jimOrders(orders): serve_time = []

    for i, v in enumerate(orders):
        serve_time.append([v[0]+v[1],i+1])
    
    serve_time.sort()
    order = [x[1] for x in serve_time]
    return order
    

    my solution in python 3, pretty simple

    7|
    Permalink
  • kashish_121
    2 years ago+ 1 comment

    Satisfies "If two fans get the burger at the same time, then print the smallest numbered order first" without any extra condition.

    vector<int> jimOrders(vector<vector<int>> orders) {
    int n=orders.size();
    vector<pair<int,int>> sum(n);
    for(int i=0;i<n;i++)
    {
        sum[i].first=orders[i][0]+orders[i][1];
        sum[i].second=i+1;
    }
    sort(sum.begin(), sum.end());
    vector<int> index(n);
    for(int i=0;i<n;i++)
    {
        index[i]=sum[i].second;
    }
    return index;
    }
    
    4|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature