Intuition
If you are wondering how two messages/words produce the same morse code - it’s because there’s no space or delimiter while generating a code for a word.
In a real setting, due to some delimiter (most probably space) - two distinct words will have two distinct morse codes.
Use a set to store computed codes, and return the number of distinct codes.
Code
Python3
Big O Analysis
-
Runtime
The runtime complexity here is where N is number of words, and k is variable length of each word.
-
Memory
The memory usage is since we are using a set to store computed cipher code.
— A