digits holding a large number (possibly with leading zeros), and an array code of length 10: when recoded, digit d turns into digit code[d].
You may pick **one** contiguous stretch of the string and recode every digit in it, or recode nothing at all. Return the string you get with the best choice, the one representing the largest possible number.digits="4721", code=[0, 1, 5, 3, 6, 5, 6, 7, 8, 9] → '6751'
4 → 6 helps, 7 → 7 is neutral, 2 → 5 helps, 1 → 1 is neutral: recoding the whole string gives 6751.
digits="381", code=[0, 9, 2, 1, 4, 5, 6, 7, 3, 9] → '389'
Recoding 3 would turn it into 1, and 8 would become 3, so we recode just the last digit: 1 → 9, giving 389.
digits="70", code=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0] → '70'
Any recoding only makes the number smaller, so we leave it as is.
digits consists of the digits 0–9 onlydigits="4721", code=[0, 1, 5, 3, 6, 5, 6, 7, 8, 9]
'6751'
Run checks the first 3 tests in your browser. Submit checks all 127 tests on the server, hidden ones included.