← All questions
MediumCoding

Boats to Save People

Asked atIDFC FIRST BankMeta
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Sort people by weight and place pointers at the lightest and heaviest.
  2. 02The heaviest remaining person must take the next boat.
  3. 03Pair that person with the lightest only if they fit, then count one boat.
  4. 04Send the heaviest alone when even the lightest remaining person cannot fit.

Reference answer

Then expect these follow-ups

  • Why must the heaviest remaining person be handled now?

    Tests: greedy proof

  • What changes if a boat can carry three people?

    Tests: problem complexity

Hiring now

Backend engineer roles are open right now

landed applies to roles like these for you, on each company’s own site, with answers written for the role.

Get 5x interviews10 free auto-applies. No card.
  • Founding Engineer (AI + Backend) - Remote, India

    Openbenchmarks · Remote

  • Software Engineer I, Backend (Continuous Delivery)

    Affirm · Remote Canada

  • Senior Software Engineer – Python Backend & Manufacturing Systems

    Diamond Foundry · Bay Area, California

Or practice this question first

Next question