Practice/Meta/Leetcode 192. Word Frequency
CodingMust
You are building a log analysis tool that processes server log files. Given a text file where each line contains one or more lowercase words separated by spaces, your task is to count how many times each distinct word appears across all lines and output the results in a specific format.
The output should list each unique word followed by its frequency count, with results sorted in descending order by frequency. Words with the same frequency can appear in any order relative to each other.
This is a practical shell scripting challenge commonly used to assess your ability to work with Unix command-line tools for text processing.
word countExample 1:
` Input: apple banana apple cherry banana apple
Output: apple 3 banana 2 cherry 1
Explanation: "apple" appears 3 times, "banana" appears 2 times, and "cherry" appears once. Results are sorted by frequency in descending order. `
Example 2:
` Input: hello world hello
Output: hello 2 world 1
Explanation: "hello" appears twice and "world" appears once. `
Example 3:
` Input: the quick brown fox jumps over the lazy dog the quick brown
Output: the 3 quick 2 brown 2 fox 1 jumps 1 over 1 lazy 1 dog 1
Explanation: "the" is most frequent with 3 occurrences, followed by "quick" and "brown" with 2 each, and the remaining words appear once. `