I recently found a question that went something like:
"Given an array of strings, return the number of distinct strings in that array."
I came up with this solution:
1. Get number_of_strings, which equals the number of strings in the input array
2. Get number_of_non_redundant, which equals the length of the input array cast as a set
3. Return 2 times number_of_non_redundant - number_of_strings
So, my question is, does this algorithm work for all data sets?
number_of_non_redundantis already the answer?