Please read the instructions carefully before starting the exam.
Once you start the exam, the timer will begin, and you cannot pause it.
Ensure that you complete and submit your code within the given time if the timer is enabled.
A customer support system stores user messages in a database. Before saving, the messages need to be sanitised to remove extra spaces, ensure consistent formatting, and replace prohibited words. Your task is to implement a message sanitiser that prepares these messages for storage.
Write a function that takes a message string and a list of prohibited words. The function should:
"****"
(case insensitive).message
(length ≤ 1000 characters).prohibitedWords[]
(case insensitive, length ≤ 100).A sanitised version of the message that follows the above rules.
Example 1:
message = " hello world! this is a sample message. badword1 should not appear. " prohibitedWords = ["badword1", "badword2"]
Output:
"Hello world! This is a sample message. **** should not appear."
Example 2:
message = "THIS is a test message. it contains BADword2 and should be clean." prohibitedWords = ["badword2"]
Output:
"This is a test message. It contains **** and should be clean."
Example 3:
message = "no bad words here. just extra spaces." prohibitedWords = []
Output:
"No bad words here. Just extra spaces."
Example 4:
message = " why is THIS happening? fix the problem!" prohibitedWords = []
Output:
"Why is this happening? Fix the problem!"
1 ≤ |message| ≤ 1000
0 ≤ |prohibitedWords| ≤ 100
Handle punctuation correctly. Sentences are separated by .
, !
, or ?
. Preserve punctuation. Match prohibited words case-insensitively and replace them entirely with "****"
.