Dsa
Backtracking
Medium
Exact Time Bridge Crossing
N people need to cross a bridge at night. They have one torch. At most two people can cross at a time, and they must carry the torch. When two people cross, they move at the speed of the slower person. The torch must be brought back by someone. Given the crossing time for each person and a target time T, determine if it is possible for everyone to be on the other side in EXACTLY T minutes. Print 'YES' or 'NO'.
Example:
Input:
15 3
5 5 5
Output:
YES
(Explanation: 1 and 2 cross (5 min), 1 returns (5 min), 1 and 3 cross (5 min). Total = 15.)
Key concepts
backtrackingstate-spacebitmask
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now