Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank, Algorithm Solutions of Problem Solving Section in Java. At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.
In this post, you will find the solution for Jim and the Orders in Java-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.
Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.
Introduction To Algorithm
The word Algorithm means “a process or set of rules to be followed in calculations or other problem-solving operations”. Therefore Algorithm refers to a set of rules/instructions that step-by-step define how a work is to be executed upon in order to get the expected results.
Advantages of Algorithms:
- It is easy to understand.
- Algorithm is a step-wise representation of a solution to a given problem.
- In Algorithm the problem is broken down into smaller pieces or steps hence, it is easier for the programmer to convert it into an actual program.
Link for the Problem – Jim and the Orders– Hacker Rank Solution
Jim and the Orders – Hacker Rank Solution
Problem:
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 to , 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.
For example, there are customers in line. They each receive an order number and a preparation time .:
Customer 1 2 3 4 5 Order # 8 5 6 2 4 Prep time 3 6 2 3 3 Calculate: Serve time 11 11 8 5 7
We see that the orders are delivered to customers in the following order:
Order by: Serve time 5 7 8 11 11 Customer 4 5 3 1 2
Function Description
Complete the jimOrders function in the editor below. It should return an array of integers that represent the order that customers’ orders are delivered.
jimOrders has the following parameter(s):
- orders: a 2D integer array where each is in the form .
Input Format
The first line contains an integer , the number of customers.
Each of the next lines contains two space-separated integers, an order number and prep time for .
Constraints
![Jim and the Orders in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct] 2 image 108](https://technorj.com/wp-content/uploads/2021/12/image-108.png)
Output Format
Print a single line of space-separated customer numbers (recall that customers are numbered from to ) that describes the sequence in which the customers receive their burgers. If two or more customers receive their burgers at the same time, print their numbers in ascending order.
Sample Input 0
3 1 3 2 3 3 3
Sample Output 0
1 2 3
Explanation 0
![Jim and the Orders in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct] 3 image 107](https://technorj.com/wp-content/uploads/2021/12/image-107-1024x212.png)
Sample Input 1
5 8 1 4 2 5 6 3 1 4 3
Sample Output 1
4 2 5 1 3
Explanation 1
Jim and the Orders – Hacker Rank Solution
import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Scanner; import java.util.Set; /** * @author Techno-RJ * */ public class JimAndTheOrders { public static void main(String[] args) { Map<Integer, Integer> hmap = new LinkedHashMap<Integer, Integer>(); Scanner sc = new Scanner(System.in); int N = sc.nextInt(); for (int i = 1; i <= N; i++) { int key = i; int value = sc.nextInt() + sc.nextInt(); hmap.put(key, value); } Set<Entry<Integer, Integer>> set = hmap.entrySet(); List<Entry<Integer, Integer>> list = new ArrayList<Entry<Integer, Integer>>(set); Collections.sort(list, new Comparator<Entry<Integer, Integer>>() { public int compare(Entry<Integer, Integer> e1, Entry<Integer, Integer> e2) { return e1.getValue().compareTo(e2.getValue()); } }); for (Entry<Integer, Integer> i : list) { System.out.print(i.getKey() + " "); } sc.close(); } }