×

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. Write a program that processes a given message and returns the sanitised version.

Task:

Implement a function that takes a string message and performs the following operations:

  • Remove extra spaces (leading, trailing, and multiple spaces between words).
  • Ensure the first character of each sentence is capitalised.
  • Replace prohibited words with "****".

Input:

  • A string message with a maximum length of 1000 characters.
  • A list of prohibited words (case insensitive).

Output:

A sanitised string that follows the rules above.

Example:

Input:

Message: " hello world! this is a sample message. badword1 should not appear. "

Prohibited words: ["badword1", "badword2"]

Output:

"Hello world! This is a sample message. **** should not appear."

Constraints:

  • Length of the message: 1 ≤ |message| ≤ 1000
  • Number of prohibited words: 0 ≤ |prohibited_words| ≤ 100

Notes:

- Sentences in the message end with punctuation marks (e.g., ., !, ?).
- The program should preserve punctuation but adjust spacing and capitalisation accordingly.
- Prohibited words should be replaced completely, regardless of case (e.g., "badword" matches "BadWord").


Time Left:



Processing...

Error:


                

Output:

Test Case Result Input Correct Output Your Output




Submission Result