Unofficial C Solution to Problem 2.2 in Cracking the Coding Interview (5th Edition)

20 Apr

In the book, the author introduces many different methods. As the author indicates, the two-pointer iterative solution is the best. In contrast, the recursive method is less effective but quite interesting. It might be useful in some cases. I only implement these two solutions, as iterative and recursive respectively. In both solutions, the return value is the same. The recursive method is as following.

The iterative method is more effective.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please put your code into a <pre>YOUR CODE</pre> section. Thanks and Happy Coding!