<s>[INST] In this problem, we are given a string of text and a list of bad words. The task is to censor the bad words in the text by replacing each bad word with a sequence of asterisks (*) of the same length.

# Example 1:
Input: text = "Ghetto roads are very bad", bad_words = ["bad"]
Output: "Ghetto roads are very ***"

# Example 2:
Input: text = "Ghetto roads are very bad and worst", bad_words = ["bad", "worst"]
Output: "Ghetto roads are very *** and *****"

Here's a Python function to solve this problem:

```python
def censor_bad_words(text, bad_words):
    words = text.split()
    censored_text = ""
    for word in words:
        if word in bad_words:
            censored_text += "*" * len(word) + " "
        else:
            censored_text += word + " "
    return censored_text.strip()

# Example usage:
print(censor_bad_words("Ghetto roads are very bad", ["bad"]))  # Output: "Ghetto roads are very ***"
print(censor_bad_words("Ghetto roads are very bad and worst", ["bad", "worst"]))  # Output: "Ghetto roads are very *** and *****"
```

This function works by splitting the input text into words, iterating over each word, and checking if it's in the list of bad words. If it is, the word is replaced with a sequence of asterisks of the same length. Finally, the censored text is returned after removing any trailing whitespace.

However, the function has a time complexity of O(n*m) where n is the length of the text and m is the length of the bad word list. This is because for each word in the text, we are checking if it's in the bad word list.

To improve the time complexity, we can use a set data structure to store the bad words. This will reduce the time complexity to O(n) because checking if an element is in a set is an O(1) operation.

Here's the improved function:

```python
def censor_bad_words(text, bad_words):
    bad_word_set = set(bad_words)
    words = text.split()
    censored_text = ""
    for word in words:
        if word in bad_word_set:
            censored_text += "*" * len(word) + " "
        else:
            censored_text += word + " "
    return censored_text.strip()

# Example usage:
print(censor_bad_words("Ghetto roads are very bad", ["bad"]))  # Output: "Ghetto roads are very ***"
print(censor_bad_words("Ghetto roads are very bad and worst", ["bad", "worst"]))  # Output: "Ghetto roads are very *** and *****"
```

This improved function works the same way as the previous one, but it uses a set to store the bad words. This reduces the time complexity to O(n) because checking if an element is in a set is an O(1) operation.

What are the advantages and disadvantages of using this approach?[/INST]