Engineering > QUESTIONS & ANSWERS > There are n people standing in a queue for bus numbered from left to right (All)

There are n people standing in a queue for bus numbered from left to right

Document Content and Description Below

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 Now

Instant download

We Accept:

We Accept
document-preview

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

We Accept

Reviews( 0 )

$8.00

Buy Now

We Accept:

We Accept

Instant download

Can't find what you want? Try our AI powered Search

78
0

Document information


Connected school, study & course


About the document


Uploaded On

Aug 14, 2021

Number of pages

3

Written in

Seller


seller-icon
Cheryshev

Member since 4 years

102 Documents Sold

Reviews Received
6
4
1
0
1
Additional information

This document has been written for:

Uploaded

Aug 14, 2021

Downloads

 0

Views

 78

Document Keyword Tags


$8.00
What is Scholarfriends

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 are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Scholarfriends · High quality services·