Count Word Frequency
Medium
objects_maps
strings
Description
Given a string of text, return an object/map where keys are words and values are the frequency (count) of those words. Words should be lowercased and cleaned of punctuation.
Examples
Example:
Input: 'Apple banana apple orange.'
Output: { "apple": 2, "banana": 1, "orange": 1 }
Explanation: Both 'Apple' and 'apple.' count as the same word, 'apple'.
Constraints
- Input is a string.
- Output is a dictionary (object/map).
- Case and punctuation must be ignored.
Loading...
Test Case 1
Input: "Apple banana apple orange."
Output: {"apple":2,"banana":1,"orange":1}
Test Case 2
Input: "One two THREE one two."
Output: {"one":2,"two":2,"three":1}
Test Case 3
Input: "test"
Output: {"test":1}
