Description
Given a string s, perform all given replacements simultaneously at specified indices. Only replace if the expected source string matches at that index.
Examples
Input:
s="abcd", indices=[0,2], sources=["a","cd"], targets=["eee","ffff"]Output:
"eeebffff"Explanation:
Replace 'a' at 0, 'cd' at 2.
Input:
s="abcd", indices=[1], sources=["a","cd"], targets=["eee","ffff"]Output:
"eeebffff"Explanation:
Edge case with a single-element array.
Input:
s="hello world", indices=[6,0], sources=["world","hello"], targets=["universe","hi"]Output:
hi universeExplanation:
Replace 'hello' at index 0 with 'hi' and 'world' at index 6 with 'universe'. Note that replacements are processed by index order, so index 0 is processed first, then index 6.
Constraints
- •
1 ≤ s.length ≤ 1000