Here’s a simple algorithm:
- Create an empty
int[]
array of length26
, it will be initialized with0
s - Iterate your String
- Get the
char
at the current index. - Tricky part: You need a mapping between a given
char
and its corresponding index (e.g.a
would be index0
,b
would be index1
and so on). Have a look at an ASCII-Table for this - Add 1 to the element at the mapped index of the created array.
- At the end, iterate the array and only print the values that are not
0
along with the correspondingchar
at that index (Need the ASCII mapping again here)