Letter Frequency
InterviewTime limit1sMemory limit1024 MB
Given up to 20 lowercase words, find the most frequent letter at each position, listing all tied letters in alphabetical order.
- Level
Easy3 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Problem
The most common consonants in English are R, T, N, S, and L. The most common vowels are E, A, and I. It is definitely fun to find the most common letters.
Given a set of words, find the letter that occurs the most in each position. That is, the most frequent letter at Position 1 when considering all the words, the most frequent letter at Position 2 when considering all the words, etc. If more than one letter is the most frequent for a particular position (i.e., ties for max at that position), print those letters in alphabetical order.
Input
The first input line contains an integer, (), indicating the number of words. Each of the next input lines contains a word. Assume that each word contains 1-30 lowercase letters and it starts in column one.
Output
Print each position and the letter(s) that occur the most in that position, in the format shown in the sample output. Each output line starts with a number, immediately followed by a colon (':'), followed by a space, followed by a letter. If there are multiple letters for an output line, they are separated by exactly one space.