Practice Largest Number After Mutating Substring
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
You are given a string num, which represents a large integer. You are also given a 0-indexed integer array change of length 10 that maps each digit 0-9 to another digit. More formally, digit d maps to digit change[d]. You may choose to mutate a single substring of num. To mutate a substring, replace each digit num[i] with the digit it maps to in change (i.e. replace num[i] with change[num[i]]). Return a string representing the largest possible integer after mutating (or choosing not to) a single substring of num. A substring is a contiguous sequence of characters within the string.
Source: Largest Number After Mutating Substring on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
num = "132", change = [9,8,5,0,3,6,4,2,6,8]
"832"
# Example 2
num = "021", change = [9,4,3,5,7,2,1,9,0,6]
"934"
# Example 3
num = "5", change = [1,4,7,5,3,2,5,6,9,4]
"5"
Constraints
Related LeetCode Problems
Practice more problems similar to Largest Number After Mutating Substring.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.