Largest Number After Mutating Substring LeetCode solution in C++
1// change first longest encountered substring from left which can make string2// greater in value3class Solution {4public:5string maximumNumber(string num, vector<int> &change) {6int n = num.size();7for (int i = 0; i < n; i++) {8int x = num[i] - '0';9if (x < change[x]) { // checking whether mutating this char will increment10// the value or not11// the mutation continues till mutating the char will increase the value12while (i < n and num[i] - '0' <= change[num[i] - '0']) {13num[i++] = change[num[i] - '0'] + '0';14}15// break the loop when substring ends16break;17}18}19return num;20}21};