class Solution: def minSteps(self, s, t): # as it's only lowercase letters, we can simply count both then compare s_letters = [0] * 26 t_letters = [0] * 26 for a in s: s_letters[ord(a) - 97] += 1 for a in t: t_letters[ord(a) - 97] += 1 # we could go either way and the answer should be the same but let's turn t into s: # we could count the deletions needed and the additions needed, and they should cancel # out because they are equal length # so easier to count absolute difference and then halve it. edit = 0 for x in range(0, 26): edit += abs(s_letters[x] - t_letters[x]) return edit // 2 s = Solution() print("Expected: 1") print("Got:", s.minSteps("aba", "bba"))