+ 3
Challenge : Find largest formed number from given numbers in an array.
Write a program that accepts list of non negative integers, arranges them such that they form the largest possible number. For example, given [50, 2, 1, 9], the largest formed number is 95021.
14 Réponses
+ 12
+ 4
my view on the challenge.
https://code.sololearn.com/cZ24Q62ArDRS/?ref=app
(bug for [2 21 29] fixed.) thanks to @Stephen for pointing out.
+ 4
Everyone doing this challenge should try [10,1] as an input. The correct answer for this is [1,10] (which gives 110 as the formed number). If you're just string sorting the array, it won't work for this input in many languages.
Credit to Yuri for posting this as a comment on Domagoj's code. Other inputs that also find the same flaw: [a, ab] where ab is a 2 digit number and a>b.
+ 2
@stephen you're right, mine doest actually work didn't think about that
+ 2
should work now
https://code.sololearn.com/c9XBhvh6Fc6q/?ref=app
+ 2
Here is my try with python
Just input numbers of list with one space
https://code.sololearn.com/cGX0v3vOT749/?ref=app
+ 2
It does not work with big arrays as long unsigned are limited in size, but at least it is a number (not a string)
https://code.sololearn.com/c9Ea8erpeMDP/?ref=app
+ 1
+ 1
No one posted C++ yet, so:
https://code.sololearn.com/ckOgBqJSY3J6/?ref=app
0
This is not spam.
https://www.sololearn.com/Discuss/583904/?ref=app
0
I have a slightly functional algorithm right now. So far, a good amount of the time, it works, but in a few instances I'm getting a maximum recursion depth exceeded error in Python. Once I figure that out, I will post mine
Edit: I'm super close to finishing, but I'm going to class now. Should have it ready later tonight.
Edit: Taking much longer than I thought. Once I fix one bug, another seems to show up. I will get this perfect though, mark my words.
0
I finished it. At last. Code will come soon, Overwatch calls me.
0
Bam. Checks for valid input, and works for every possible size of array and any values given into the array (unless it gets time exceeded, not sure when it starts doing that) but it def works. This was surprisingly hard
Edit: Removed the function of swapping each individual number to make it's biggest form. Domagoj mentioned that wasnt a part of this, I thought it was because of a comment on here that I misunderstood xP Works exactly how it should still, just without the swapping of individual numbers.
https://code.sololearn.com/cZE00vUVUph1/?ref=app