Interview 02

Determine if a string is full of unique characters.

Specifications

Feature Tasks

Stretch Goal

If they solve this question too quickly, increase the difficulty by saying that the sentence is case sensitive. (i.e. “A” and “a” are not the same. )

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
The quick brown fox jumps over the lazy dog FALSE
I love cats TRUE
Donald the duck FALSE

Documentation

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

Solution

Algorithm Parse the input string and read each value, add each character to our Hashset as we iterate. For each character in the string, check if Hashset includes the character. If Hashset includes character, return false. If Hashset does not include character, add it and continue on to next character in the input string. If we reach the end of our input string, and find no matches in our Hashset, return true.
Pseudocode
algorithm HAS_UNIQUE_CHARACTERS
  declare string STRING <- input string
  declare Hashset UNIQUE <- new Hashset for storing unique characters
  for each CHARACTER in STRING:
    if CHARACTER is included in UNIQUE:
      return false
    else
      add CHARACTER to UNIQUE
  return true
Big O Since we need to read all values present in the input string, this method requires a time complexity of 0(n). And since we are storing all characters in a Hashset, at worst case we would store all characters in another structure, so our space complexity would also reach 0(n).