Problem Statement:
Write a program that reads a text file, finds
the most frequently occurring word,
and prints it along with its count.
Example File (input.txt):
apple banana apple PinE. orange
Banana apple orange pine Banana pine
Orange "Pine" PIn'e. Pine!
Expected Output:
Most Frequent Word: pine
Count: 6
Explanation:
1. Read the file line by line using BufferedReader.
2. Extract words, convert them to lowercase, and clean them (removing
punctuation).
3. Use a HashMap to count occurrences of each word.
4. Find the word with the highest count. 5. Print the most frequent word and
its count.
Edge Cases Considered:
✔If the file is empty, print "No words found". ✔If multiple words have the
same frequency, it prints the first encountered one.
✔Handles punctuation and ignores case (treats "Apple" and "apple" as the
same).
Time Complexity:
.Reading the file: O(N) (N = number of words
in the file)
.Storing words in Hasimap: O(N)