Skip to content
Programmingoneonone
Programmingoneonone

LEARN EVERYTHING ABOUT PROGRAMMING

  • Home
  • CS Subjects
    • IoT ? Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

LEARN EVERYTHING ABOUT PROGRAMMING

HackerRank Jim and the Orders problem solution

YASH PAL, 31 July 2024

In this HackerRank Jim and the Orders problem solution, Jim’s Burgers has a line of hungry customers. Orders vary in the time it takes to prepare them. Determine the order the customers receive their orders. Start by numbering each of the customers from 1 to n, front of the line to the back. You will then be given an order number and a preparation time for each customer.

The time of delivery is calculated as the sum of the order number and the preparation time. If two orders are delivered at the same time, assume they are delivered in ascending customer number order.

HackerRank Jim and the Orders problem solution

Topics we are covering

Toggle
  • Problem solution in Python.
  • Problem solution in Java.
  • Problem solution in C++.
  • Problem solution in C.

Problem solution in Python.

def solve():
    n = int(input())
    a = [(tuple(map(int, input().split()))) for _ in range(n)]
    a = [(i + 1, a[i][0], a[i][1]) for i in range(n)]
    a = [(x[0], x[1] + x[2]) for x in a]
    a = sorted(a, key=lambda x: x[1])
    a = [x[0] for x in a]
    print(" ".join(list(map(str,a))))
    
    
solve()

{“mode”:”full”,”isActive”:false}

Problem solution in Java.

import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] o=new int[n];
        boolean[]oo=new boolean[n];
        int[] sol=new int[n];
        for(int i=0;i<n;i++)
            {
            o[i]=(in.nextInt()+in.nextInt());
            oo[i]=false;
        }
        for(int c=0;c<n;c++)
            {
           int best=o[c];
            int r=1;
        for(int i=0;i<n;i++)
            {
            
            if(c!=i&&o[c]>o[i])
                {
                r++;
            }
        }
            if(oo[r-1])
                {
                r++;
            }else{
                oo[r-1]=true;
            }
            sol[r-1]=c+1;
        }
        for(int c=0;c<n;c++)
            {
            System.out.print(sol[c]+" "); 
        }
        
        
    }
}

{“mode”:”full”,”isActive”:false}

Problem solution in C++.

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;
int n;
int main(){
    int i,j,k;
    scanf("%d",&n);
    vector<pair<int,int> > v;
    for(int i = 0; i < n; ++i){
        scanf("%d%d",&j,&k);
        v.push_back(make_pair(j+k, i+1));
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < v.size(); ++i){
        pair<int,int> p = v[i];
        if(i)printf(" ");
        printf("%d", p.second);
    }
    printf("n");
    return 0;
}

{“mode”:”full”,”isActive”:false}

Problem solution in C.

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

typedef struct {
    int t, i;
} pair;
pair a[1000001];

int cmp(const void *a, const void *b) {
    return ((pair *)a)->t - ((pair *)b)->t;
}

int main()
{
    int n, i, p, q;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d%d", &p, &q);
        a[i].i = i;
        a[i].t = p + q;
    }
    qsort(a, n, sizeof(pair), cmp);
    for (i = 0; i < n; i++)
        printf("%d ", a[i].i + 1);
    return 0;
}

{“mode”:”full”,”isActive”:false}

Algorithms coding problems solutions

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes