Interview 01

Determine the most common word in a book.

Specifications

Feature Tasks

Edge Cases

Structure

Familiarize yourself with the grading rubric, so you know how to score the interview.

Look for effective problem solving, efficient use of time, and effective communication with the whiteboard space available.

Every solution might look a little different, but the candidate should be able to test their solution with different inputs to verify correctness.

Assign points for each item on the Rubric, according to how well the candidate executed on that skill.

Add up all the points at the end, and record the total at the bottom of the page.

Example

Input Output
In a galaxy far far away far
Taco cat ate a taco taco
No. Try not. Do or do not. There is no try. No

Documentation

Record detailed notes on the rubric, to share with the candidate when the interview is complete.

Solution

Algorithm Create a Hash Table with words as keys, and integers as values. This will store the number of occurrences for words found in the input string. Iterate through the input string. Either parse the string or use Regex to find all discreet words within the input string. For each word read, increment the value in the Hash Table. After you're finished iterating, read all values from the Hash Table. return the word that is associated with the hightest value stored in the Table.
Pseudocode
algorithm MOST_COMMON_WORD:
  declare string BOOK <- input string
  declare hashtable WORD_COUNT <- new HashTable storing words as keys and integers as values
  for each WORD in BOOK:
    if WORD_COUNT contains the key WORD:
      increment WORD_COUNT at WORD by 1
    else
      add WORD to WORD_COUNT as key with 1 as value
  return the highest value in WORD_COUNT
Big O Depending on the length of the input book, we will read and store more words in our Hash Table. If we iterate through our book once to tally up the word count, and perhaps again when we find the largest value in the Hash Table we will have a run time complexity of 0(n). Since we are storing all words in a Hash Table, we will also have a space complexity of 0(n) as well.