Problem 134217 · easy · Level 01 Prerequisites & Setup

Bleep the Bad Word

strings · replace · repetition · len

Given text and a word, return text with every occurrence of word replaced by a run of asterisks of the same length. Matching is exact and case-sensitive; word is never empty. Occurrences are found from left to right and never overlap: after a match, the search continues just after it.

Examples

Input:  text = "darn it, darn!", word = "darn"
Output: "**** it, ****!"

Input:  text = "hello", word = "xyz"
Output: "hello"

Input:  text = "baaad", word = "aa"
Output: "b**ad"
Explanation: "aa" is found at index 1; the search continues at index 3, so the overlapping "aa" at index 2 is not a match.

Constraints

  • 0 <= len(text) <= 5000
  • 1 <= len(word) <= 20
  • both may contain letters, digits, spaces and punctuation

Goals

  • Replace every occurrence of a substring
  • Build a replacement of the right length with `*`
Starting Python…