Engineering > QUESTIONS & ANSWERS > There are n people standing in a queue for bus numbered from left to right (All)
Question There are n people standing in a queue for bus numbered from left to right 1 to n.Each person has a patience limit p, and will only wait until the time p expires. If bus reache... s after time p person will leave the queue and miss the bus. Intially bus is empty and has capacity k,Given a number of queries q, where each query is a time bus arrival,q[i] for each query print the index/number(1-indexed) of the k th person who catches the bus.If all passengers remaining in the queue can board the bus,return 0 because there will be no kth person. For Example,Given a bus size k=2,patience limits of p =[1,2,3,4] and queries at times q =[1,3,4],there are three scenerios all dealing with the same intial queue.Where the bus arrives at q [0]=1,all passengers are still queued but only first two will fit on the bus.The last passenger who will fit is number 2.If the bus arrives at q[1]=3,passengers 1 and 2 have left the queue,the first two remaining (3 and 4) get on the bus,filling it to capacity.when q[2]=4,passengers 1,2 and 3 have left,so passenger 4 can get on.Since the bus is not filled, there is no kth passenger.The returned array of answer is [2,4,0]. public static List<Integer> kthPerson(int k, List<Integer> p, List<Integer> q) { } [Show More]
Last updated: 2 years ago
Preview 1 out of 3 pages
Buy this document to get the full access instantly
Instant Download Access after purchase
Buy NowInstant download
We Accept:
Can't find what you want? Try our AI powered Search
Connected school, study & course
About the document
Uploaded On
Aug 14, 2021
Number of pages
3
Written in
This document has been written for:
Uploaded
Aug 14, 2021
Downloads
0
Views
78
In Scholarfriends, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Scholarfriends · High quality services·