Find the Smallest Number in Java
The challenge
You have a positive number n
consisting of digits. You can do at most one operation: Choosing the index of a digit in the number, remove this digit at that index and insert it back to another or at the same place in the number in order to find the smallest number you can get.
#Task: Return an array or a tuple or a string depending on the language (see “Sample Tests”) with
-
- the smallest number you got
-
- the index
i
of the digitd
you took,i
as small as possible
- the index
-
- the index
j
(as small as possible) where you insert this digitd
to have the smallest number.
- the index
Example:
|
|
126235
is the smallest number gotten by taking 1
at index 2
and putting it at index ``
29917
is the smallest number gotten by taking 2
at index `` and putting it at index 1
which gave 029917
which is the number 29917
.
|
|
The solution in Java code
Option 1:
|
|
Option 2:
|
|
Option 3:
|
|
Test cases to validate our solution
|
|
Additional test cases
|
|