5 kyu

Find the smallest

1,589 of 5,748g964

Description:

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

    1. the smallest number you got
    1. the index i of the digit d you took, i as small as possible
    1. the index j (as small as possible) where you insert this digit d to have the smallest number.

Examples:

smallest(261235) --> [126235, 2, 0] or (126235, 2, 0) or "126235, 2, 0"

126235 is the smallest number gotten by taking 1 at index 2 and putting it at index 0

smallest(209917) --> [29917, 0, 1] or ...

[29917, 1, 0] could be a solution too but index `i` in [29917, 1, 0] is greater than 
index `i` in [29917, 0, 1].

29917 is the smallest number gotten by taking 2 at index 0 and putting it at index 1 which gave 029917 which is the number 29917.

smallest(1000000) --> [1, 0, 6] or ...

Note

Have a look at "Sample Tests" to see the input and output in each language

Fundamentals

More By Author:

Check out these other kata created by g964

Stats:

CreatedMay 16, 2016
PublishedMay 16, 2016
Warriors Trained49788
Total Skips13297
Total Code Submissions131252
Total Times Completed5748
Ruby Completions210
Python Completions1589
JavaScript Completions1154
CoffeeScript Completions6
Java Completions695
C# Completions424
Haskell Completions84
Clojure Completions35
Elixir Completions61
C++ Completions473
TypeScript Completions200
PHP Completions200
Crystal Completions9
F# Completions30
C Completions265
Swift Completions100
R Completions27
Shell Completions22
OCaml Completions14
Groovy Completions12
Scala Completions65
Julia Completions19
Go Completions103
Nim Completions11
Racket Completions7
Reason Completions3
VB Completions10
Kotlin Completions78
Rust Completions89
Pascal Completions7
Perl Completions7
Elm Completions6
D Completions4
COBOL Completions4
Erlang Completions5
Prolog Completions7
Total Stars1317
% of votes with a positive feedback rating84% of 896
Total "Very Satisfied" Votes664
Total "Somewhat Satisfied" Votes169
Total "Not Satisfied" Votes63
Total Rank Assessments9
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • g964 Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • user5036852 Avatar
  • MDabrowski1990 Avatar
  • Voile Avatar
  • FArekkusu Avatar
  • monadius Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • akar-0 Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad