Given a positive integer num
within the range of 1
to 2,000,000,000
, find the smallest integer greater than num
that contains exactly the same digits as num
. If such a number does not exist or is outside the allowed range, return -1
.
Input: 123 Output: 132
Input: 321 Output: -1
Input: 59876 Output: 65789