Cutshort Interview Question

Pirate Gold Distribution Problem - The algorithm