Loading...
Loading...
Loading...
Parcels wait in a delivery queue, stored in a LinkedList. In each round the parcel at the front goes to the back of the queue. After k rounds, print the queue from front to back.
Example
Input
5 P1 P2 P3 P4 P5 2
Output
P3 P4 P5 P1 P2
P1 and P2 each went from the front to the back.
Try the problem first. Open one hint at a time.
removeFirst() returns the front parcel and addLast(...) puts it at the back; both are O(1) on a LinkedList.
After n rounds the queue is the same as at the start, so only k % n rounds are needed.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor