Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

Determine character frequency in the given string

Problem description :

Create a character frequency analysis table for the given string.

Input : A string // “foo bar”
Output : A JSON // {” “: 1, a: 1, b: 1, f: 1, o: 2, r: 1}

Logic :

  • Create a charFrequency hash table
  • Iterate through string
    • If the character exist in charFrequency hash table then update the frequency
    • Else add the entry into the hash table and initialize its value to 1
    • return charFrequency.

Solution :

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *