call(back)
Algorithms & Data StructureseasySign in to star problems

Count Each Character in First-Seen Order

Write each character's total count followed by the character, in first-seen order: compressTotals(s).

compressTotals("AAABBAA")   // "5A2B"
compressTotals("BAB")       // "2B1A"

Inputs contain letters only.

Hints

Hint 1

Count into a Map. It keeps insertion order, which is exactly first-seen order.

Asked at