DAYS
HOUR
MINS
SEC
Error
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 geeks" Explanation: 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|
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes