When Did the Canoe Leave?
Updated
Problem statement
Two friends paddle a canoe on a river whose current flows downstream at currentMph miles per hour. They always paddle at the same speed v in still water, so they move at v - currentMph going upstream and v + currentMph going downstream.
- On day 1 they paddle upstream for
upstreamHourshours, then downstream fordownstreamHourshours. - On day 2 they paddle
returnMilesmiles upstream and arrive exactly back at the point where day 1 began, atarrivalHour:arrivalMinuteon a 24-hour clock.
Return the time they left on day 2 as a string "H:MM": the hour without a leading zero (0 to 23) and the minutes as two digits. Round the day 2 travel time to the nearest whole minute, with exactly half a minute rounding up. If the trip takes them back past midnight, keep counting backward on the clock (for example, 1 hour before 0:30 is 23:30).
If no speed v makes them faster than the current, return "IMPOSSIBLE".
Function
canoeDepartureTime(upstreamHours: int, downstreamHours: int, returnMiles: int, currentMph: int, arrivalHour: int, arrivalMinute: int) → StringExamples
Example 1
upstreamHours = 3downstreamHours = 4returnMiles = 48currentMph = 3arrivalHour = 8arrivalMinute = 30return = "6:30"This is the interview trip. Day 1 ends 4(v + 3) - 3(v - 3) = v + 21 miles below the start, and that must be 48, so v = 27.
Going back upstream at 27 - 3 = 24 mph, 48 miles take 2 hours. Arriving at 8:30 means leaving at 6:30.
Example 2
upstreamHours = 3downstreamHours = 4returnMiles = 24currentMph = 3arrivalHour = 8arrivalMinute = 30return = "IMPOSSIBLE"Now v + 21 = 24, so v = 3, the same as the current. Going upstream they would not move at all, so the answer is "IMPOSSIBLE".
Example 3
upstreamHours = 1downstreamHours = 2returnMiles = 30currentMph = 1arrivalHour = 0arrivalMinute = 15return = "23:06"Day 1 ends 2(v + 1) - (v - 1) = v + 3 miles below the start, so v = 27 and they go upstream at 26 mph.
30 miles take 30 / 26 hours, about 69.23 minutes, which rounds to 69. One hour and nine minutes before 0:15 is 23:06 on the clock.
Constraints
1 <= upstreamHours < downstreamHours <= 1001 <= returnMiles <= 10^60 <= currentMph <= 1000 <= arrivalHour <= 230 <= arrivalMinute <= 59
More Susquehanna International Group (SIG) Online Assessment questions
- Catch Fish with Reusable BaitsOA · Seen Nov 2026
- Bold Play to Reach a GoalOA · Seen Nov 2026
- Cats, Truth and Who Has MoreOA · Seen Nov 2026
- Counting Cows by Their LegsOA · Seen Nov 2026
- Enough Muffins for the LineOA · Seen Nov 2026
- Expected Consecutive Pairs Among Chosen NumbersOA · Seen Nov 2026
- Four-by-Four Boundary GridOA · Seen Nov 2026
- Frog Paths Without Long RunsOA · Seen Nov 2026
- Higher Roll, or Lose the SumOA · Seen Nov 2026
- Is a Popular Story Fake?OA · Seen Nov 2026
Similar questions at other companies
- Count Prime Values in SubtreesVisa · OAVisa interview questions
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Server Upgrade PlanningWells Fargo · OAWells Fargo interview questions
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Gaussian Naive Bayes Classifier (Machine Learning OA)Pinterest · OAPinterest interview questions
- Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
- Count Lucky TicketsThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Task Scheduler with CooldownGoDaddy · OA