Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
489 views

For proper oa or interview experiences list of all top tech companies visit :

https://oa.desiqna.in

https://interview.desiqna.in

 

image

 

in Online Assessments by Expert (46,090 points) | 489 views

2 Answers

0 like 0 dislike
Best answer

Images of ques

image
image

by Expert (46,090 points)
0 like 0 dislike
b_t=0                                    # the earliest time when the bridge is empty for use
stack=[(0,1,0) for _ in range(worker)]   # (time, bank, -1 * trips to/from the new house)
task=[[t3,t4],[t1,t2]]                   # bank= 0,1 for the old, new side. Smaller (time, bank, -trip) is selected first
while box:     
    t,bank,trip=heapq.heappop(stack)
    box-= 1-bank                         # box decreases by 1 if one crosses from the old side,
    t = b_t = max(t,b_t)+task[bank][0]            
    t+=task[bank][1]                     # cross from the new (old) side, need t1+t2 (t3+t4) back to the bridge. 
    if box==0:
        return t 
    heapq.heappush(stack, (t,1-bank,trip-bank))
by Expert (46,090 points)