Word count solution using frequencies