Ad
  • Default User Avatar

    I believe that shaunpatterson's solution is O(n). The counting of occurences of each character with the for loop is O(n). Then we traverse the (character, count) pairs to find the characters that appear more than once. This is O(1) because there is at most 36 characters (26 alphabets and 10 digits). Finally, we count the characters that appear more than once, which is again O(1). So we have that the whole thing is O(n) + O(1) + O(1) = O(n).

  • Custom User Avatar

    I think yours is O(n^2) for worst case too, because once you look at all the chars of text, then you check all the elements of your dict.