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

16 Apr

There are two solutions for this question. The first one is with hash table, thus needs more space but less time. The second one needs no additional space but more time.

In the first solution, I choose to use the uthash library, because its simplicity. With hash table, the time used to find duplicate item would be O(1).

In the second solution, I did not use hash table. Thus its time complexity is O(n^2), and space complexity is O(1).

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!