Practice Find And Replace in String
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Apply the replacements described by parallel arrays indices, sources and targets to the original string s. For each i, replace sources[i] with targets[i] only if sources[i] matches exactly starting at indices[i]; otherwise skip that replacement. Evaluate all matches and indices against the original s, so one replacement never shifts another. Replacements are guaranteed not to overlap. Return the resulting string.
Source: Find And Replace in String on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s = "abcd", indices = [0, 2], sources = ["a", "cd"], targets = ["eee", "ffff"]
"eeebffff"
# Example 2
s = "abcd", indices = [0, 2], sources = ["ab","ec"], targets = ["eee","ffff"]
"eeecd"
Constraints
Related LeetCode Problems
Practice more problems similar to Find And Replace in String.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.