donnemartin / interactive-coding-challenges

120+ interactive Python coding interview challenges (algorithms and data structures). Includes Anki flashcards.
Other
29.57k stars 4.46k forks source link

str_diff challenge failing tests when returning expected result #301

Closed andar1an closed 2 years ago

andar1an commented 2 years ago

My initial attempt to solve this challenge is below:

from collections import Counter

class Solution(object):

    def find_diff(self, str1, str2):
      if str1 is None or str2 is None:
        return TypeError("Strings were not provided")
      c1 = Counter(str1)
      c2 = Counter(str2)
      if len(c1) > len(c2):
        for item in c1.items():
          if item not in c2.items():
            return item[0]
      else:
        for item in c2.items():
          if item not in c1.items():
            return item[0]

If I manually create the class and test the method I get the correct response for the following assertions (they fail in test cell - not sure why yet):

        self.assertEqual(solution.find_diff_xor('ab', 'aab'), 'a')
        self.assertEqual(solution.find_diff_xor('aab', 'ab'), 'a')
        self.assertEqual(solution.find_diff_xor('abcd', 'abcde'), 'e')
        self.assertEqual(solution.find_diff_xor('aaabbcdd', 'abdbacade'), 'e')

A few examples of return values: image image

andar1an commented 2 years ago

I realized assertion was looking for another method, my mistake.

KrakenDev0001 commented 10 months ago

Was this because of the find_diff_xor method? I noticed it never mentioned it in the challenge overview, but it still checked for it. I deleted it because there also wasn't a placeholder in the code block for it, so I'm assuming it was kept in by mistake? I just cloned the repo, so I'm trying to make sure I didn't do the challenge wrong.

andar1an commented 10 months ago

I honestly don't remember this, sorry.