Count frequency of each character in the input string

Asked atSBS
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Clarify case, whitespace, and character set rules.
  2. 02Initialize a frequency map or bounded array.
  3. 03Increment once per character.
  4. 04Preserve a requested output order.
  5. 05State encoding and complexity assumptions.

Reference answer

Then expect these follow-ups

  • Should 'A' and 'a' be combined?

    Tests: follow-up reasoning

  • How would you count Unicode grapheme clusters?

    Tests: implementation extension

Hiring now

SBS has 37 open roles right now

landed applies to roles like these for you, on each company’s own site, with answers written for the role.

Get 5x interviews10 free auto-applies. No card.
  • Principal Systems Architect I

    Sofia, BG

  • Senior Systems Engineer II

    Noida, IN

  • Manager, Tax

    Scottsdale, AZ, US

Or practice this question first

Next question