finished: took a long time on recursion. finally use two pointers to AC