+ 12
[Challenge] - maximal number
Make a program that takes a list of integers and reorders them to create the largest integer possible from concatenating them Example: 50,22,3,9 becomes 950322 (Question 4 out of “Five programming problems every Software Engineer should be able to solve in less than 1 hour”)
16 ответов
+ 14
Remember that you can submit this as an assignment using Lesson Factory. :>
+ 7
https://code.sololearn.com/cm8u7tfjRVS7/?ref=app
+ 6
+ 5
Here is my solution in python
https://code.sololearn.com/c28rvOlF18eE/?ref=app
Extra challenge:
Make sure your solution covers the case of:
420,42,423
+ 5
@Daniel Peleg
There still is a trouble in your method :
take this input :
a = "2,32,1,9,50,509,5013"
your code gives 95050950133221 as the solution
while 95095050133221 is bigger.
the '9' in '509' is involved.
A simple brute force way to solve the question is :
a = "2,32,1,9,50,509,5013"
print(max(''.join(i)for i in permutations(a.split(','))))
(or you can replace 'a' with 'input()' if you prefer - I don't). But an elegant, non-brute-force solution would be nicer.
+ 3
@Daniel You can get to the Lesson Factory by accessing the button with three dots at the top-right corner of your screen, at your launch screen (usually your activity feed). It is next to your notification button, the one which leads to "Settings".
+ 3
@Cestpasgrave you are right. I have to add another condition to the if statement
edited it.
now it's right
the conditions are quite hard to read because that line is a bit long,
but the logic should be clear enough
+ 2
@Daniel Peleg
To answer 'how do I do that', you can read here :
https://www.sololearn.com/Discuss/1137151/?ref=app
it's about Lesson Factory
+ 2
hheerrss..mine
https://code.sololearn.com/c7Rr0NcYV1k4/?ref=app
+ 1
How do I do that ?
+ 1
sounds a lot like a sorting algorithm...
+ 1
Very late I know - I'm definitely not a software engineer!
https://code.sololearn.com/cBkIDh0HaLHM/?ref=app
0
https://code.sololearn.com/c00j3prC07E4/#py
I did this and later found out that I read the question wrong. This is a way to get the maximal number from the combination of all the digits in the list.
Will attempt the actual problem now :P lol