Practice Time to Cross a Bridge
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Move n boxes from the right warehouse to the left using k workers initially waiting left. Worker i has times [leftToRight,pick,rightToLeft,put]. Only one crosses at once; picking and putting can overlap other work. When free, the bridge first admits a waiting right-side worker, otherwise a waiting left-side worker if boxes remain unassigned. Within a side, prioritize larger leftToRight+rightToLeft, then larger worker index. Never dispatch more workers than remaining boxes. Return when the final box reaches the left bank, excluding its putting time. Practice approach: Use priority queues for waiting workers on each side and completion-time queues for workers picking or putting. Move every finished worker into a waiting queue before selecting a crossing. When nobody can cross, jump to the next completion time. Track boxes assigned separately from boxes delivered.
Source: Time to Cross a Bridge on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
n = 2, k = 1, time = [[2,3,4,5]]
23
The first box reaches the left bank at 2+3+4=9. Putting finishes at 14; the second trip reaches left at 14+2+3+4=23. Its final putting time is excluded.
Constraints
Related LeetCode Problems
Practice more problems similar to Time to Cross a Bridge.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.