Smaller Number With The Same Digits Medium

+100 PTS

Before you start the test, check out our tutorial challenge

  • TYPE CODE PRACTICE CHALLENGE
  • LANGUAGES C++, C#, JAVA, JAVASCRIPT AND 6 MORE
    LANGUAGES C++, C#, JAVA, JAVASCRIPT, PHP, PYTHON, PYTHON2, RUBY, SWIFT, TYPESCRIPT
  • TIME ~25MIN

Smaller Number With The Same Digits

Challenge outline

Hello and welcome to the challenge!


Write a code that receives a positive integer number and returns the next smaller positive integer number formed from the same digits. Return -1 if that's impossible.

Examples

  • solve(51) -> 15
  • solve(232) -> 223
  • solve(444) -> -1

Input

  • the given number

Output

  • -1 or the next smaller number made from the same digits


You can solve this programming contest in C++, C#, Ruby, JavaScript, Python and many other languages. If you want, you can also take part in other November 2019 competitions. Below you can find some of them:



Have fun and good luck! :)