×

Instructions

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.


Customer Support Message Sanitisation - Strings (Difficulty - Easy)


Customer Support Message Sanitisation

Problem Statement:

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.

Task:

Write a function that takes a message string and a list of prohibited words. The function should:

  • Remove leading, trailing, and multiple consecutive spaces.
  • Capitalize the first character of each sentence.
  • Replace prohibited words with "****" (case insensitive).

Input:

  • A string message (length ≤ 1000 characters).
  • An array of prohibited words prohibitedWords[] (case insensitive, length ≤ 100).

Output:

A sanitised version of the message that follows the above rules.

Examples:

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!"
        

Constraints:

  • 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 "****".


Time Left:



Processing...

Error:


                

Output:

Test Case Result Input Correct Output Your Output




Submission Result