Dsa
Strings
Easy
String Character Frequency
Given a string, return a dictionary where the keys are characters in the string and the values are their frequency in the string. Ignore spaces.
Input Format:
- A single line containing the string s (1 <= |s| <= 1000).
Output Format:
- Print the dictionary of characters and their frequencies, sorted by character.
Example:
Input:
hello world
Output:
{'d': 1, 'e': 1, 'h': 1, 'l': 3, 'o': 2, 'r': 1, 'w': 1}
Key concepts
stringscounting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now