Dsa
Hashing
Medium
Word Frequency Count
Calculate the frequency of each word in a given text input. The input consists of multiple lines, and the words are separated by spaces. The output should be a list of words and their counts, sorted alphabetically.
Input:
Multiple lines where each line is a string of words.
Output:
A list of words accompanied by their frequency, sorted by the word.
Example:
Input:
'hello world'
'hello'
'world again'
Output:
[['again', 1], ['hello', 2], ['world', 2]]
Key concepts
hashingstringscounting
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