Tap here to switch tabs
Problem
Submissions

Problem: Maximum Value after Insertion

med
30 min
Try to solve the Maximum Value after Insertion problem.

Statement

You are given a string n representing a large integer and a single integer digit x.

Insert the digit x at any position in n so that the numerical value of the resulting number is maximized. You cannot alter the relative order of the existing digits in n.

Return a string representing the maximum possible value after inserting x.

Constraints:

  • 1≤1 \leq n.length ≤105\leq 10^5

  • 1≤1 \leq x ≤9\leq 9

  • The digits in n are in the range [1,9][1, 9].

  • n is a valid representation of an integer.

  • In the case of a negative n, it will begin with '-'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Value after Insertion

med
30 min
Try to solve the Maximum Value after Insertion problem.

Statement

You are given a string n representing a large integer and a single integer digit x.

Insert the digit x at any position in n so that the numerical value of the resulting number is maximized. You cannot alter the relative order of the existing digits in n.

Return a string representing the maximum possible value after inserting x.

Constraints:

  • 1≤1 \leq n.length ≤105\leq 10^5

  • 1≤1 \leq x ≤9\leq 9

  • The digits in n are in the range [1,9][1, 9].

  • n is a valid representation of an integer.

  • In the case of a negative n, it will begin with '-'.