Cutshort interview question

Pirate Gold Distribution Problem - The algorithm