LeetCode192: Word Frequency

Link: https://leetcode.com/problems/word-frequency/

assume that words.txt has the following content:

the day is sunny the the
the sunny is is

Your script should output the following, sorted by descending frequency:

the 4
is 3
sunny 2
day 1

# Read from the file words.txt and output the word frequency list to stdout.
cat words.txt | tr -s ‘ ‘ ‘\n’ | sort | uniq -c | sort -nrk 1 | awk ‘{ print $2, $1 }’

Attention:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s