Lafler & Kinman algorithm