Problem · Array

Minimum Tunnel Crossing Time

Learn this problem
EasyArcesium logoArcesiumFULLTIMEOA

Problem 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 soloTime seconds.
  • Two people may cross together only when the sum of their heights is strictly less than tunnelHeight; that crossing takes pairTime seconds.

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) → int

Examples

Example 1

heights = [1,3,4,4,2]tunnelHeight = 9soloTime = 4pairTime = 6return = 16

Pair 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 = 10

One 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.
  • soloTime and pairTime are positive.

More Arcesium problems

drafts saved locally
public int minimumTunnelTime(int[] heights, int tunnelHeight, int soloTime, int pairTime) {
  // Write your code here.
}
heights[1,3,4,4,2]
tunnelHeight9
soloTime4
pairTime6
expected16
checking account