Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .

0 like 0 dislike
1,071 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 (44,360 points)

2 Answers

0 like 0 dislike
 
Best answer

Images of ques

image
image

by Expert (44,360 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 (44,360 points)
...