Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6420
@blackshadows 6380
@mb1973 5704
@Quandray 5245
@akhayrutdinov 5111
@saiujwal13083 5046
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3523
@mantu_singh 3510
@sushant_a 3459
Complete Leaderboard
Replace a word
Easy Accuracy: 69.55% Submissions: 391 Points: 2

Given three strings S, oldW and newW. Find all occurrences of the word oldW in S and replace them with word newW.

Example 1:

Input: 
S = "xxforxx xx for xx"
oldW = "xx"
newW = "Geeks"
Output: 
"geeksforgeeks geeks for geeksExplanation: 
Replacing each "xx" with
"Geeks" in S.

Example 2:

Input: 
S = "india is the xx country"
oldW = "xx"
newW = "best"
Output: 
"india is the best country"
Explanation: 
Replacing each "xx" with
"best" in S.


Your Task:  
You dont need to read input or print anything. Complete the function ReplaceAll() which takes S, oldW and newW as input parameters and returns the string S after replacing all oldW with newW.

Expected Time Complexity: O(n2)
Expected Auxiliary Space: O(1)

Constraints:
1<= |S| <=1000
1<= |oldW|, |newW| <=|S|

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Replace a word

Output Window