+ 33

CHALLENGE : REARRANGING THE DIGITS 4⃣5⃣0⃣1⃣7⃣➡️1⃣0⃣4⃣5⃣7⃣

Level: easy Task: Find the smallest number (not leading zeros) and largest number which can be obtained by rearranging the digits of given number (positive integer). For example: Input: 300591 Output: 100359 smallest 953100 largest All languages are welcome! https://code.sololearn.com/c4p2nSUQdKAG/?ref=app https://code.sololearn.com/c9Hd9bhAXvXc/?ref=app

8th Nov 2017, 6:31 PM
LukArToDo
LukArToDo - avatar
41 ответ
+ 8
here is my code, works for negative numbers too. Kinda did it more complicated than needed but oh well https://code.sololearn.com/cWYcRlyjTdJv/?ref=app
8th Nov 2017, 10:24 PM
Jeremy
Jeremy - avatar
+ 17
Here is my answer in Java: https://code.sololearn.com/c9wV0j9u4eP6
8th Nov 2017, 8:52 PM
Vahid Shirbisheh
Vahid Shirbisheh - avatar
8th Nov 2017, 8:22 PM
David Akhihiero
David Akhihiero - avatar
+ 12
Here's my C# implementation! ✌ Interesting challenge with non-leading zero! I've tried something new this time with custom helper function and lazy generator. Besides, it works for negative number too. Enjoy~ ❤ https://code.sololearn.com/cFKnOEFinL93/?ref=app
9th Nov 2017, 9:36 AM
Zephyr Koo
Zephyr Koo - avatar
+ 12
@ ~swim~ Buddy, do not disturb yourself, it will always be a haters 😞
16th Nov 2017, 3:01 PM
LukArToDo
LukArToDo - avatar
+ 12
@ ~swim~ I agree with you 👍
16th Nov 2017, 4:54 PM
LukArToDo
LukArToDo - avatar
9th Nov 2017, 11:05 AM
Käzî Mrîdùl Høssäîn
Käzî Mrîdùl Høssäîn - avatar
10th Nov 2017, 6:51 AM
AZTECCO
AZTECCO - avatar
+ 8
https://code.sololearn.com/cd5E2rxu7Z39/?ref=app
8th Nov 2017, 8:51 PM
Podretyz
Podretyz - avatar
+ 7
Here's a simple Python solution: def getSmallest(number): if number[0] != '0': return "".join(number) else: count = 0 for n in number: if n == '0': count += 1 else: break return "".join(number[count:count+1] + number[:count] + number[count+1:]) number = sorted(list(input("Enter a sequence of digits: "))) print() print("Smallest:", getSmallest(number)) number.reverse() print("Largest:", "".join(number))
8th Nov 2017, 7:43 PM
ChaoticDawg
ChaoticDawg - avatar
8th Nov 2017, 8:48 PM
Alex Dobrin
Alex Dobrin - avatar
+ 6
https://code.sololearn.com/cApo0Iva8L9i/?ref=app
9th Nov 2017, 1:42 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 5
@Ferhat nice, but you should join to make it 1 number instead of unpacking, and the smallest should not have leading zeros.
8th Nov 2017, 7:54 PM
ChaoticDawg
ChaoticDawg - avatar
+ 5
#I don't have any experiences at kind of problems because I haven't coded before. I got using loop from ChaoticDawg's. So half is my try: https://code.sololearn.com/cV7HIH5NM116/?ref=app
9th Nov 2017, 11:08 AM
Ferhat Sevim
Ferhat Sevim - avatar
+ 5
what do you think about my code? I am a beginner in coding. https://code.sololearn.com/c52n0809FzYZ/?ref=app
9th Nov 2017, 3:06 PM
Dmitry Yarmolinsky
Dmitry Yarmolinsky - avatar
9th Nov 2017, 5:20 AM
bobbie
bobbie - avatar
9th Nov 2017, 7:28 AM
Bill Fisher
+ 4
https://code.sololearn.com/csthvgUNNajH/?ref=app
9th Nov 2017, 11:44 AM
Sunil Yadav
Sunil Yadav - avatar
+ 4
Kind of a manual solution, but this is my Java try: https://code.sololearn.com/cauyz717ni9O/?ref=app
10th Nov 2017, 11:56 AM
Lucho Greppi
Lucho Greppi - avatar
12th Nov 2017, 2:12 PM
Kartik
Kartik - avatar