Problem 134217 · easy · Phase 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.

Examples

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

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

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…