+ 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
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
+ 17
Here is my answer in Java:
https://code.sololearn.com/c9wV0j9u4eP6
+ 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
+ 12
@ ~swim~
Buddy, do not disturb yourself, it will always be a haters 😞
+ 12
@ ~swim~
I agree with you 👍
+ 9
+ 8
https://code.sololearn.com/cd5E2rxu7Z39/?ref=app
+ 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))
+ 6
My try in javascript:
https://code.sololearn.com/WBQYwWpQkg1Z/?ref=app
+ 6
https://code.sololearn.com/cApo0Iva8L9i/?ref=app
+ 5
@Ferhat nice, but you should join to make it 1 number instead of unpacking, and the smallest should not have leading zeros.
+ 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
+ 5
what do you think about my code? I am a beginner in coding.
https://code.sololearn.com/c52n0809FzYZ/?ref=app
+ 4
My First Challenge
https://code.sololearn.com/WYSQ84uug6xu/?ref=app
+ 4
https://code.sololearn.com/csthvgUNNajH/?ref=app
+ 4
Kind of a manual solution, but this is my Java try:
https://code.sololearn.com/cauyz717ni9O/?ref=app
+ 4
Here's my try
https://code.sololearn.com/cISnWrgbB9a4/?ref=app