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.
Topics
Asked at
Sign in to use the assistant — ask what the problem means, get a hint when you're stuck, or have your current work reviewed. Conversations save to your account.