Dsa
Strings
Hard
Substring Replacement
Replace all non-overlapping occurrences of a given substring within a string with another substring. Your task is to read the original string, the target substring, and the replacement substring, then output the modified string.
Input Format:
- The first line contains the original string.
- The second line contains the target substring.
- The third line contains the replacement substring.
Output Format:
- The modified string after replacement.
Example:
Input:
Hello World
World
Earth
Output:
Hello Earth
Key concepts
stringsreplacementsubstrings
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now