Learn
Exam

Remove Substring

Difficulty
STARTER

Problem

Given a string word and a substring target, write a function solution that returns the result of removing target from word. Note that target appears only once in word.


Constraints

  • The length of word is between 1 and 100 inclusive.
  • The length of target is between 1 and the length of word inclusive.
  • word and target consist only of lowercase English letters.

Test Case

Test Case Number word target return
1 "banana" "b" "anana"
2 "abcdef" "cde" "abf"
3 "hello world" " " "helloworld"

Explanation for Test Case 1

  • When word = "banana" and target = "b", removing "b" results in "anana".

Explanation for Test Case 2

  • When word = "abcdef" and target = "cde", removing "cde" results in "abf".

Explanation for Test Case 3

  • When word = "hello world" and target = " " (space), removing " " results in "helloworld".