FastPrepSorted Character Frequencies
Problem · String

Sorted Character Frequencies

Learn this problem
EasyDeloitte logoDeloitteNEW GRADOA

Problem 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) → String

Examples

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 <= 100000
  • word contains only lowercase English letters.

More Deloitte problems

drafts saved locally
public String sortedCharacterFrequencies(String word) {
    // Write your solution here.
}
word"hello"
expected"e1h1l2o1"
checking account