4 kyu
Next smaller number with the same digits
4,206 of 11,791LesRamer
Description:
Write a function that takes a positive integer and returns the next smaller positive integer containing the same digits.
For example:
next_smaller(21) == 12
next_smaller(531) == 513
next_smaller(2071) == 2017
Return -1 (for Haskell
: return Nothing
, for Rust
: return None
), when there is no smaller number that contains the same digits. Also return -1 when the next smaller number with the same digits would require the leading digit to be zero.
next_smaller(9) == -1
next_smaller(135) == -1
next_smaller(1027) == -1 # 0721 is out since we don't write numbers with leading zeros
- some tests will include very large numbers.
- test data only employs positive integers.
The function you write for this challenge is the inverse of this kata: "Next bigger number with the same digits."
Strings
Mathematics
Algorithms
Similar Kata:
Stats:
Created | Nov 28, 2015 |
Published | Dec 3, 2015 |
Warriors Trained | 52974 |
Total Skips | 12108 |
Total Code Submissions | 131973 |
Total Times Completed | 11791 |
JavaScript Completions | 3538 |
C# Completions | 1131 |
Java Completions | 1624 |
Haskell Completions | 133 |
Python Completions | 4206 |
Ruby Completions | 250 |
Rust Completions | 301 |
C Completions | 640 |
Crystal Completions | 11 |
COBOL Completions | 8 |
Go Completions | 169 |
D Completions | 5 |
Scala Completions | 11 |
Total Stars | 2006 |
% of votes with a positive feedback rating | 94% of 1526 |
Total "Very Satisfied" Votes | 1355 |
Total "Somewhat Satisfied" Votes | 149 |
Total "Not Satisfied" Votes | 22 |
Total Rank Assessments | 8 |
Average Assessed Rank | 4 kyu |
Highest Assessed Rank | 3 kyu |
Lowest Assessed Rank | 5 kyu |