Minimum Tunnel Crossing Time
Reported by candidates from Arcesium's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this Arcesium OA, reported July 2025, is pairing everyone you can without checking if pairing even pays off. Candidates see a tunnel, a height limit, and jump straight into a matching routine. But the cost structure decides everything. If pairTime is at least twice soloTime, pairs are pointless. If it's cheaper, you want the maximum number of valid pairs. It's a sort plus two pointers problem wearing a story. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the idea below is short enough to carry in your head.
The problem
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 = 9 soloTime = 4 pairTime = 6 return = 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 = 9 soloTime = 4 pairTime = 6 return = 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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
First, compare costs. If pairTime >= 2 * soloTime, return n * soloTime, done. Otherwise every pair saves time, so maximize the number of pairs. Sort heights, then run two pointers: left at the shortest, right at the tallest. If heights[left] + heights[right] < tunnelHeight, pair them, move both inward. If not, the tallest person can't pair with anyone (even the shortest fails), so they go solo and right moves in. Total is pairs * pairTime + solos * soloTime. The common pitfall is skipping the cost check and always pairing, which fails when pairing is expensive. Another is a greedy that pairs adjacent sorted values, which wastes short people on short people. Example 1 sorts to 1,2,3,4,4 and yields two pairs plus one solo, 16. If the two-pointer logic slips under pressure, StealthCoder is the hedge for the live OA.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Minimum Tunnel Crossing Time cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Arcesium's OA.
Arcesium reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Tunnel Crossing Time FAQ
What's the trick in Minimum Tunnel Crossing Time?+
Check the cost first. If a pair costs at least two solo crossings, everyone goes alone. Otherwise sort and use two pointers to form the maximum number of valid pairs, with leftovers crossing solo. The pairing count is the whole problem.
How hard is this Arcesium question really?+
Easy to medium. The code is about fifteen lines once you see it. The difficulty is noticing the cost comparison and proving the greedy pairing of tallest with shortest maximizes pairs. Most misses come from skipping that comparison.
Why pair the tallest with the shortest?+
The tallest person is the hardest to place. If even the shortest can't join them, nobody can, so they go solo. If the shortest can, using that pairing costs nothing, since the shortest is the most flexible partner for everyone else.
What's the time complexity?+
Sorting dominates at O(n log n). The two-pointer sweep is O(n) and space is O(1) beyond the sort. No dynamic programming is needed because maximizing pair count under a threshold is a classic greedy.
How do I prepare for this in 48 hours?+
Practice the sort and two-pointer pairing pattern on boat-style problems. Write it out once, then test edge cases: one person, all pairs invalid, and pairTime equal to twice soloTime. That covers nearly every failure mode.