So I was tasked the following:
Given a list of strings, output a sorted string that consists of all lowercase characters (a-z) from each string in the list.
[aba, xz] -> aabxz
I tried this:
from collections import Counter from string import ascii_lowercase def merge(strings): counter = Counter() for string in strings: for char in string: counter[char] +=1 result =  for c in ascii_lowercase: if c in counter: for _ in range(counter[c]): result.append(c) return "".join(result)
This works on most test cases, but times out on a couple test cases. I am extremely frustrated. How can I improve the time complexity of this solution?