I got the below problem (alphabet soup) as my data structure course exercise.
https://github.com/kennedyCzar/AlphabetSoup-Using-Django
I solved it in O(m+s) where m is the length of the message and s is the length of the soup (I just created a table from the soup and decided if the message can be created or not using that table)
def checkBowl(message, soup):
d = {}
# O(S)
for c in soup:
d[c] = d.get(c, 0) + 1
# O(m)
for c in message:
if(d.get(c, 0) == 0):
return False
else:
d[c] -= 1
# So the overall time complexity is O(m+s)
return True
but it seems the given GitHub solved it in O(mlogm) however I think his/her solution is in O(m*s) cause he/she just didn't consider python's in operator works in O(length of the list).
By the way can someone please hint, is that possible to solve this problem with a better time complexity? (the problem specified that the bowl of soup may be very large)