Since we are to find uncommon words - words that appear in both the sentences only once. We can use a frequency counter to keep track of the frequencies of words of both sentences, and return the ones that have a frequency of 1.
Code
Python3
Big O Analysis
-
Runtime
The runtime complexity here is where N is length of string s1 and M is length of string s2.
-
Memory
The memory usage is since we use the
collections.defaultdict
object to store the frequencies.
— A