You are working for Michael Burry as he is preparing to short tesla against their bull run. However the investors in the fund are anxious and demand what is the maximum value tsla stock can still go up. You are tasked to fake this number.
Given the positive integer n the value of tsla stock right now , find the smallest integer which has exactly the same digits existing in this integer n but is greater in value than n. If no such positive integer exists, return -1.
Please note that the returned integer should fit in 32-bit integer, Even if there is a valid answer , if it does not fit in 32-bit integer, return -1.
Important : You need to write the solution as a function that takes the integer n as the argument and returns the required number as the result. Take a look at the c++ template for an example.
21 is the required number containing the same amount and same digits as 12 but less than any other possible integer created by these digits.
1 <= n <= 231 - 1