#K63162. Most Frequent Key
Most Frequent Key
Most Frequent Key
You are given a keyboard layout consisting of distinct characters and a text string. Your task is to determine the most frequently used key in the text according to the order of keys in the provided keyboard layout.
If two or more keys have the same maximum frequency, the key that appears first in the keyboard layout is chosen.
If the text is empty (i.e., contains no characters), output None
.
The frequency counting follows the formula: $$\text{frequency}(c)=\#\{i\,|\, text[i]=c\}.$$
inputFormat
The input is given via stdin and consists of two lines:
- The first line contains a string representing the keyboard layout.
- The second line contains the text string to be analyzed.
outputFormat
Output the most frequently used key according to the keyboard layout on stdout. If the text is empty, output None
.
abcdefghijklmnopqrstuvwxyz
a
a