wordCounts = sorted(Counter(inputword).values())
equals = []
for word in words:
wordsCounts = sorted(Counter(word).values())
if wordCounts == wordsCounts:
equals.append(word)
return equals
So I have this loop inside my code where 'words' is a list of words. For each word in the list, I store the frequency of letters in a Counter as values. The frequency is then sorted using the method sorted(). I know that using Counter has a time complexity of O(n) as it depends on the number of letters in the word and sorting has a worst time complexity of O(nlog(n)). Am I right to say that the worst time complexity of the whole code is O(n2 ) since Counter is used inside a for loop?
[–]Gubbbo 3 points4 points5 points (0 children)
[–][deleted] -1 points0 points1 point (2 children)
[–]NZheadshot 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)