-
Notifications
You must be signed in to change notification settings - Fork 243
Pirate Message Check
kyra-ptn edited this page Aug 25, 2024
·
4 revisions
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.
- What is the desired outcome?
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`.
- Forgetting to remove whitespace from the message before checking.
- Not accounting for possible empty messages which should return
False
.
def can_trust_message(message):
alphabet_set = set('abcdefghijklmnopqrstuvwxyz')
message_set = set(message.replace(" ", "))
return alphabet_set.issubset(message_set)