Skip to content

Files

Latest commit

Aug 16, 2024
1e1f1d8 · Aug 16, 2024

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Feb 8, 2024
Aug 16, 2024
Feb 8, 2024
Feb 17, 2024
Aug 16, 2024

Next smaller number


Given is a positive integer n 10 18 . You are asked to find the largest integer m such that m < n and m has the same digits as n . If there is no such m , then the output should be 1 . Also return 1 if the next smaller number with the same digits has a leading zero. You are not allowed to use a sorting algorithm.


Examples

Input: 632
Output: 623

Input: 123656789
Output: 123598766

Input: 100
Output: -1