Given a string S on which you need to perform Q replace operations. Each replacement operation has 3 parameters: a starting index i, a source word x and a target word y. The rule is that if x starts at position i in the original string S, then we will replace that occurrence of x with y. If not, we do nothing.
Note: All these operations occur simultaneously. It’s guaranteed that there won’t be any overlap in replacement: for example, S = “abc”, indexes = [0,1], sources = [“ab”, “bc”] is not a valid test case.
Time : O(qlogq + n) in avg O(qlogq + n^2) in worst