Problem · String
Sorted Character Frequencies
Learn this problemProblem statement
You are given a lowercase English word word. Count how many times each distinct character occurs.
Return one string formed by listing the distinct characters in ascending alphabetical order, immediately followed by each character's decimal frequency.
Function
sortedCharacterFrequencies(word: String) → StringExamples
Example 1
word = "hello"return = "e1h1l2o1"The distinct letters are e, h, l, and o in alphabetical order, with frequencies 1, 1, 2, and 1.
Example 2
word = "zzzaabb"return = "a2b2z3"Alphabetical ordering places a and b before z.
Example 3
word = "aaaaaaaaaaaa"return = "a12"A frequency may contain more than one decimal digit.
Constraints
1 <= word.length <= 100000wordcontains only lowercase English letters.