Approach 1: Counting

Intuition and Algorithm

Every uncommon word occurs exactly once in total. We can count the number of occurrences of every word, then return ones that occur exactly once.

Complexity Analysis

  • Time Complexity: , where are the lengths of A and B respectively.

  • Space Complexity: , the space used by count.

Analysis written by: @awice.