Loading...
Loading...
A typing tutor shows which keys you press most. Read a line and count how many times each letter appears, ignoring case. Print the letters that appear at least once, in alphabetical order, one per line as letter: count with the letter in small form. If the line has no letters, print No letters.
No letters.Example 1
Input
Hello World
Output
d: 1 e: 1 h: 1 l: 3 o: 2 r: 1 w: 1
H and W are counted as h and w.
Example 2
Input
123!
Output
No letters
Try the problem first. Open one hint at a time.
Lowercase the line and use an int[26]: count[ch - 'a']++ for each letter.
Loop i from 0 to 25 and print (char) ('a' + i) for every counter above 0. That gives alphabetical order for free.
Keep a flag, or add up the counters, to know whether to print No letters.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor