Codepath

Pirate Message Check

U-nderstand

Understand what the interviewer is asking for by using test cases and questions about the problem.

  • Q
    • What is the desired outcome?
    • To determine if the message contains every letter of the English alphabet at least once.
    • What input is provided?
    • A string containing lowercase English letters and whitespace.

P-lan

Plan the solution with appropriate visualizations and pseudocode.

General Idea: Use a set to track the unique letters in the message and compare it with a set of all letters in the alphabet.

1) Create a set of all letters in the English alphabet.
2) Create a set from the input message, removing any whitespace.
3) Check if the alphabet set is a subset of the message set.
4) Return `True` if it is a subset, otherwise return `False`.

⚠️ Common Mistakes

  • Forgetting to remove whitespace from the message before checking.
  • Not accounting for possible empty messages which should return False.

I-mplement

def can_trust_message(message):
    alphabet_set = set('abcdefghijklmnopqrstuvwxyz')
    message_set = set(message.replace(" ", "))
    return alphabet_set.issubset(message_set)
Fork me on GitHub