Loading Now

BasicEquationMaker

Mr. Nonequation is bad at math. He sees a string of numbers, but he cannot figure out what operator to use to make an equation.

Given a string of numbers, turn it into a valid equation by inserting only one operator (+, -, *, /, or %) and one equals sign ('=') and return it. If it is not possible, return "Not possible"instead.

The operators should be to the left of the equals sign ("=")

  • "+" denotes addition
  • "-" denotes subtraction
  • "*" denotes multiplication
  • "/" denotes non-integer division
  • "%" denotes modulus (remainder)

The operator should be place to the left of the equals sign.

It is guaranteed that there is only one possible answer. It is guaranteed that the numbers in the equation won’t contain leading zeros.

Example

  • For nums = "123123246", the output should be BasicEquationMaker(nums) = "123+123=246".
  • For nums = "113", the output should be BasicEquationMaker(nums) = "Not possible".

Input/Output

  • [execution time limit] 4 seconds (py)

  • [input] string nums

    A string of numbers.

    Constraints:

    3 ≤ nums.length ≤ 15.

  • [output] string

    • A valid equation, or "Not possible" if it’s impossible to construct one.

Post Comment

Contact