String - 19: Get the frequency of every word in given String | Java Implementation

preview_player
Показать описание
- Replace all punctuations with space
- Split string to string array by one or more space
- Create frequency map of each word

- To print Alphabetically, use TreeMap which'll sort based on word
- To Print Frequency wise, Use treeMap & use comparator based on frequency & compare

Time Complexity: O(n)
Space Complexity: O(n)

For more info, please see the video.

CHECK OUT CODING SIMPLIFIED

★☆★ VIEW THE BLOG POST: ★☆★

I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 500+ videos.

★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★

★☆★ Send us mail at: ★☆★
Рекомендации по теме
Комментарии
Автор

Time Complexity should be O(n+log(n)) because we also have to consider the time complexity of sorting which is being used in treeMap internally

shyamgoyal
Автор

one doubt how can we put duplicate words(key) in Hashmap

shubhamanand
join shbcf.ru