Jim and the Orders

  • + 0 comments

    Easy cpp approach:-

    vector jimOrders(vector> orders) {

    int n=orders.size();
    
    vector<int>dt(n,0);
    vector<int>cid(n,0);
    
    
    
    for (int i=0;i<n;i++)
    {
        dt[i]= orders[i][1]+orders[i][0];
        cid[i]=i+1;
    }
    
    for (int i=0;i<n-1;i++)
    {
        for (int j=0;j<n-i-1;j++)
        {
            if (dt[j]>dt[j+1])
            {
                swap(dt[j],dt[j+1]);
                swap(cid[j],cid[j+1]);
            }
        }
    }
    
    return cid;
    

    }****