PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers

Quick Overview

This question evaluates algorithmic problem-solving and optimization skills, including modeling constrained state transitions, reasoning about trade-offs under a single shared resource, and minimizing aggregate cost.

  • medium
  • NVIDIA
  • Coding & Algorithms
  • Software Engineer

Find minimum time to cross bridge with flashlight

Company: NVIDIA

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

A group of people must cross a bridge at night with **one flashlight**. The bridge can hold at most **two people** at a time. - If two people cross together, they move at the speed of the **slower** person. - The flashlight must always be carried when crossing. - Everyone starts on the same side and all must end on the other side. Given an array `t[]` of crossing times (positive integers) for each person, compute the **minimum total time** needed for everyone to cross. Clarify assumptions you will use (e.g., can people return, constraints on `n`, etc.) and describe an efficient algorithm.

Quick Answer: This question evaluates algorithmic problem-solving and optimization skills, including modeling constrained state transitions, reasoning about trade-offs under a single shared resource, and minimizing aggregate cost.

A group of people must cross a bridge at night using one flashlight. The bridge can hold at most two people at a time. If two people cross together, they move at the speed of the slower person. The flashlight must always be carried during any crossing, so people may need to return with it until everyone has crossed. Given an array `t` of positive integers where `t[i]` is the time person `i` needs to cross, return the minimum total time required for everyone to reach the other side. Assumptions used in this problem: - `t` may be unsorted. - People are allowed to return with the flashlight. - `n` may be 0. If nobody needs to cross, the answer is 0. - You only need to return the minimum total time, not the crossing sequence. - Your solution should be efficient for large `n`.

Constraints

  • 0 <= n <= 200000
  • 1 <= t[i] <= 10^9
  • The answer fits in a 64-bit signed integer

Examples

Input: ([],)

Expected Output: 0

Explanation: No one needs to cross, so the total time is 0.

Input: ([3],)

Expected Output: 3

Explanation: Only one person crosses once.

Input: ([4, 7],)

Expected Output: 7

Explanation: Both cross together, taking the slower person's time: 7.

Input: ([1, 2, 5, 10],)

Expected Output: 17

Explanation: Optimal sequence: 1 and 2 cross (2), 1 returns (1), 5 and 10 cross (10), 2 returns (2), 1 and 2 cross (2). Total = 17.

Input: ([2, 2, 2, 2],)

Expected Output: 10

Explanation: Every crossing or return takes 2. Minimum total is 2 + 2 + 2 + 2 + 2 = 10.

Input: ([8, 1, 2, 6, 12],)

Expected Output: 26

Explanation: After sorting to [1, 2, 6, 8, 12], optimally move 8 and 12 first using the two fastest as helpers, then finish the remaining three. Total = 26.

Hints

  1. Sort the crossing times first. Once sorted, the important decision is how to move the two slowest remaining people.
  2. For the two slowest people, compare these two strategies: send the two fastest as helpers, or send only the fastest back and forth.
Last updated: May 12, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • Careers
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Return all file paths via DFS - NVIDIA (easy)
  • Implement a disk space manager with eviction - NVIDIA (medium)
  • Implement encode/decode for list of strings - NVIDIA (easy)
  • Implement short algorithms on logs, grids, and strings - NVIDIA (hard)
  • Solve small string and API tasks - NVIDIA (medium)