Word Frequency Counter
Given a string 'S' consisting of words, your task is to calculate how many times each word appears in the string. A word is a series of one or more non-space characters. In 'S', words can be separated by spaces, and you may have leading or trailing spaces.
Input:
"what we think we become"
Output:
what 1
we 2
think 1
become 1
Example:
Consider the string: "what we think we become". Here, the word "what", "think", and "become" appear once, while "we" appears twice.
Constraints:
0 <= |S| <= 10^5
- Time Limit: 1 second
Note:
The output can be in any order.
Be the first one to answer
Add answer anonymously...
Top CitiusTech Java Developer interview questions & answers
Popular interview questions of Java Developer
Top HR questions asked in CitiusTech Java Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app