Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Exercise: Count words using two vectors

  • Given a string that consists of words and white-spaces, count how many times each word appears!
  • In this solution we use two vectors. A much better solution would be to use HashMap, but in this example I wanted to show the solution with two vectors.
  • One vector will hold the list of distinct words.
  • The second vector will hold the count for each word.