Intuition
This problem is sequel problem to 1974 Minimum Time to Type Word Using Special Typewriter - check that out first so this problem will get easy.
We greedily assign the most frequently typed characters to the starting positions of the keys (eg. first, second, etc).
Code
Python3
Big O Analysis
-
Runtime
The runtime complexity here is where U is the unique characters in the input string
word
. -
Memory
The memory usage is since we are using a
collections.Counter
which inherently is a dictionary.
— A