Problem · Array
Minimum Tunnel Crossing Time
Learn this problemProblem statement
A group must pass through a tunnel of height tunnelHeight. Every person's height is strictly less than the tunnel height.
A crossing may contain either one person or two people:
- One person takes
soloTimeseconds. - Two people may cross together only when the sum of their heights is strictly less than
tunnelHeight; that crossing takespairTimeseconds.
Crossings happen one after another. Return the minimum total time needed for everyone to cross.
Function
minimumTunnelTime(heights: int[], tunnelHeight: int, soloTime: int, pairTime: int) → intExamples
Example 1
heights = [1,3,4,4,2]tunnelHeight = 9soloTime = 4pairTime = 6return = 16Pair heights 1 and 4, pair heights 3 and 4, and let the remaining person cross alone. The total is 6 + 6 + 4 = 16.
Example 2
heights = [1,3,4]tunnelHeight = 9soloTime = 4pairTime = 6return = 10One valid pair crosses in 6 seconds and the remaining person crosses in 4 seconds.
Constraints
heights.length >= 1.- Every height is positive and strictly less than
tunnelHeight. soloTimeandpairTimeare positive.
More Arcesium problems
- Ordered Payload ReleaseONSITE INTERVIEW · Seen Jul 2026
- Decode Numeric StringONSITE INTERVIEW · Seen Jun 2026
- Tree Ancestor QueriesONSITE INTERVIEW · Seen Jun 2026
- City Infection NumberOA · Seen Jul 2025
- Product of Subset MaximaOA · Seen Jul 2025
- Reconstruct the Root StreamOA · Seen Jul 2025
- Add DigitsOA · Seen Aug 2023
- Binary Tree Maximum Path SumOA · Seen Aug 2023