ak4017
BAN USER- 0of 0 votes
AnswersYou are given the length and time of occurrence of packet and Queues which process packets. Total processing time for a packet is equal to the length of packet plus the waiting time in queue. For eg lets say we have only one queue for now, and A packet of length 5 comes at t = 1, and another packet of length 4 comes at t = 3. Total processing time for first packet is 5( no waiting time as queue is empty at t = 1) and at t = 3, 2 units of first packet is processed and 3 units remaining so, for second packet 3 units will be waiting time in queue plus 4 units for its length. Total processing time for 2nd packet is 7 units. If there are multiple queues you can add new packet in any of the other queues. Given the time and length of all incoming packets, we need to find the minimum no. of queues required such that total processing time of each packet is less than 10 units. Maximum possible no. of queues are 5. If you require more than 5 queues print -1.
Test Cases Format: First Line contains the number N, the total no. of packets and N following line contains two numbers ti, li where li is length of packet coming at time = ti units.
Test case1:
2
2 7
5 8
Test Case 2:
3
1 3
2 3
3 5
Test Case 3:
3
1 5
2 4
3 8
Output:
Case1: 2
Case2: 1
Case3: 2
Consider the following time table of incoming packets:time packets-length 1 8 2 5 3 2 4 6
If you put the packet in queue with minimum time then this will lead to 3 queues:
- ak4017 in United States
t = 1:
q1: 8
t = 2:
q1: 7
q2: 5
t = 3:
q1: 6
q2: 4, 2
t = 4:
q1: 5
q2: 3, 2
q3: 6
But its output should be 2 queues:
1) 8 in queue 1
2) 5 in queue 2
3) 2 in queue 1
4) 6 in queue 2| Report Duplicate | Flag | PURGE
Samsung Software Developer Algorithm