Question

Write a function to find the next number with the same digits?

Login to Submit

Examples

You're given a number. You need to rearrange its digits to form the next greater number — the smallest number larger than the given number using the same digits.
If no such number exists, return -1.

input:12  
output:21


input:21     // 21 is the highest possible using these digits.
output:-1