// Algorithm code