First implementation, two pointers, greedy algorithm