[Programming Problem] Largest Number

```Given a list of non-negative integers nums, arrange them such that they form the largest number and return it.   Since the result may be very large, so you need to return a string instead of an integer.   Example 1: Input: nums = [10,2] Output: "210"   Example 2: Input: nums = [3,30,34,5,9] Output: "9534330"```

Take two numbers, say 3 and 30. How would you decide which one would come first? You would simply compare ‘330’ and ‘303’ and decide.

Given the above comparison function, we simply sort these numbers using a custom comparator which compares two numbers in the above way. Then, just concat array and return number.

One gotcha: the system expects you to remove leading zeros. We use a regex for that.

```/** * @param {number[]} nums * @return {string} */ var largestNumber = function(nums) { nums.sort((a, b) => Number(a+""+b) > Number(b+""+a) ? -1 : 1); return nums.join("").replace(/^0*(.+)/, '\$1'); };```

61 thoughts on “[Programming Problem] Largest Number”

1. I simply desired to appreciate you once again. I’m not certain the things I could possibly have gone through without these ways discussed by you concerning that industry. It previously was an absolute alarming concern in my opinion, but seeing a new expert way you handled the issue forced me to leap for gladness. I am just happy for your advice as well as sincerely hope you know what an amazing job that you’re providing training the rest thru your websites. Most probably you haven’t got to know any of us.

2. I must express my admiration for your kind-heartedness supporting people who absolutely need help on this important concern. Your real commitment to passing the message up and down had been exceptionally practical and have in every case encouraged professionals just like me to realize their dreams. Your amazing informative guideline entails this much to me and substantially more to my office colleagues. Best wishes; from everyone of us.

3. I would like to voice my respect for your generosity in support of those individuals that should have guidance on in this situation. Your personal dedication to passing the solution up and down appeared to be astonishingly effective and have surely helped professionals like me to arrive at their dreams. Your amazing informative key points denotes a great deal to me and a whole lot more to my office colleagues. Thanks a lot; from all of us.

4. I precisely desired to say thanks yet again. I do not know the things that I could possibly have followed in the absence of the type of thoughts documented by you on my topic. It previously was a horrifying problem for me, however , observing your well-written form you treated the issue forced me to jump for delight. I’m thankful for your service as well as hope you find out what an amazing job you have been getting into training the rest through your website. Most likely you have never come across any of us.

5. I simply needed to say thanks once more. I am not sure the things that I would’ve gone through in the absence of these secrets revealed by you directly on my subject. It actually was a very alarming condition in my opinion, however , spending time with a expert tactic you processed that took me to weep over contentment. I am just happy for your information and then hope you are aware of a great job you are always providing educating most people by way of a web site. Most probably you have never come across all of us.

6. I intended to post you the little word to finally give many thanks again for your personal magnificent secrets you’ve contributed on this page. This has been so strangely open-handed with you to offer easily all that a few people might have supplied as an e book to get some money for themselves, notably seeing that you could have tried it in the event you considered necessary. The techniques in addition served to become easy way to be certain that other individuals have the same fervor similar to mine to find out a good deal more with regard to this problem. I know there are several more pleasurable sessions up front for people who go through your site.

7. I wish to point out my love for your generosity for persons who need help on the question. Your personal commitment to passing the message all around appeared to be rather powerful and have constantly helped some individuals just like me to reach their objectives. The warm and helpful key points denotes much to me and far more to my fellow workers. Many thanks; from all of us.

8. I precisely had to say thanks once more. I am not sure what I might have followed without those creative concepts documented by you concerning such theme. It was before a real frustrating concern for me personally, however , being able to see your expert mode you solved that made me to cry with happiness. Now i am happy for your information and then trust you recognize what a great job that you’re getting into instructing many people through your website. More than likely you’ve never got to know all of us.

9. I want to get across my love for your kind-heartedness in support of people who really need help with in this area. Your special dedication to getting the solution all over had been quite helpful and has always permitted others much like me to attain their goals. Your amazing warm and friendly guide means so much to me and especially to my mates. With thanks; from everyone of us.

10. I wish to point out my appreciation for your kindness in support of individuals that really need guidance on the question. Your special dedication to passing the solution along had been incredibly good and have frequently permitted workers much like me to arrive at their goals. Your insightful hints and tips entails a lot to me and especially to my mates. Warm regards; from each one of us.

11. I want to voice my respect for your kind-heartedness for folks that really want assistance with your content. Your personal dedication to passing the solution up and down had been exceedingly practical and has encouraged regular people much like me to realize their pursuits. Your amazing important guide entails much to me and even further to my fellow workers. With thanks; from all of us.

12. That means you’ll lead some fresh features and have access to additional channels where you can gain visibility, without having to modify import of some elaborate, manual migration process. https://googlec5.com

13. I wanted to post you the bit of note just to say thanks a lot once again for the spectacular thoughts you have provided on this site. It was certainly generous of you to allow without restraint just what most of us could have distributed for an e book to make some bucks on their own, chiefly considering the fact that you could have tried it in the event you desired. These solutions likewise acted like the good way to know that other people online have the same dreams just like mine to grasp a whole lot more in respect of this matter. Certainly there are several more pleasant situations in the future for those who go through your website.

14. I precisely desired to thank you very much all over again. I’m not certain the things I could possibly have carried out in the absence of these solutions discussed by you about this area of interest. It was before a real intimidating setting for me, nevertheless taking a look at a new well-written tactic you managed the issue forced me to jump with gladness. I am just thankful for this information and thus sincerely hope you find out what a powerful job you are putting in teaching most people with the aid of a site. Probably you have never met any of us.

15. Bertindak beserta slot88 lokasi slot luar praja serta
Serta karakteristik ini, Anda dapat bermain bilamana jua dengan pada mana
melulu minus ada arti keadaan. Bermain slot luar ibu pertiwi bersama tempat web SLOT
THAILANDmemiliki setengah keuntungan dibandingkan atas dolan slot online dalam negara asal
Anda. Selain itu, akun pro slot server Thailand terkadang kali mengijabkan layanan pelanggan nan lebih baik selanjutnya lebih responsif dibandingkan dan akun slot biasa.
Pada bantuan atas status tengara tempat slot gacor enteng menang, sira dapat meregistrasi akun slot online
terbaik serupa cepat, gampang beserta gratis.
Dengan akun pro slot kamboja, Anda tak perlu gelisah kembali lantaran letak slot nan mudah
menang ditawari selama hadirin yang sedia menjumpai jackpot maxwin setiap musim.

Dalami bersama geledah info bagaimanakah dialek Anda dapat pilih game slot memakai kelas RTP
tinggi nan hendak mempermudah lalu memungkinkannya Anda demi menetapkan hasil kemajuan gambling slot semakin banyak serta lebih remeh kembali.
Secara umum pilihan permainan tersebut nan akan bawa tuah lalu nasib nan mana ini hendak mempermudah kau untuk dapat secepatnya kembali bekal.

16. For the reason that the admin of this site is working, no hesitation very
quickly it will be well-known, due to its feature contents.

17. I read this paragraph fully on the topic of the resemblance of most recent
and preceding technologies, it’s amazing article.

18. SLOT GACOR
Slot Gacor Gampang Menang : Gate Of Olympus , Starlight Princess, Koi Gate , Bonanza
Provider Slot Online Terbaik : Pragmatic Play , PG Soft
Promo Unggulan : Event Scatter , Petir Merah , Bonus Begadang 78%
Pembayaran : BCA , BRI , BNI , Mandiri
E-Wallet : Dana , Ovo , Gopay , Pulsa
Minimal Deposit : Rp 25.000,-

19. SLOT GACOR
Slot Gacor Gampang Menang : Gate Of Olympus , Starlight Princess,
Koi Gate , Bonanza
Provider Slot Online Terbaik : Pragmatic Play , PG Soft
Promo Unggulan : Event Scatter , Petir Merah ,
Pembayaran : BCA , BRI , BNI , Mandiri
E-Wallet : Dana , Ovo , Gopay , Pulsa
Minimal Deposit : Rp 25.000,-

20. Your mode of telling the whole thing in this piece of writing is in fact good, every
one be able to effortlessly know it, Thanks a lot.

as well as from our dialogue made at this place.

22. Your means of explaining the whole thing in this post is really pleasant, all be capable of
easily be aware of it, Thanks a lot.

23. Having read this I thought it was very enlightening.
I appreciate you spending some time and effort to put this information together.
I once again find myself spending way too much time both reading and commenting.
But so what, it was still worth it!

24. SLOT GACOR
Slot Gacor Gampang Menang : Gate Of Olympus , Starlight Princess, Koi Gate ,
Bonanza
Provider Slot Online Terbaik : Pragmatic Play , PG Soft
Promo Unggulan : Event Scatter , Petir Merah , Bonus Begadang 78%
Pembayaran : BCA , BRI , BNI , Mandiri
E-Wallet : Dana , Ovo , Gopay , Pulsa
Minimal Deposit : Rp 25.000,-

25. SLOT GACOR
Slot Gacor Gampang Menang : Gate Of Olympus , Starlight Princess, Koi Gate , Bonanza
Provider Slot Online Terbaik : Pragmatic Play , PG Soft
Promo Unggulan : Event Scatter , Petir Merah , Bonus Begadang 78%
Pembayaran : BCA , BRI , BNI , Mandiri
E-Wallet : Dana , Ovo , Gopay , Pulsa
Minimal Deposit : Rp 25.000,-

26. At this moment I am going away to do my breakfast, when having my breakfast

27. Hey just wanted to give you a quick heads up.
The text in your content seem to be running off the screen in Ie.
I’m not sure if this is a format issue or something to do with internet browser compatibility but
I thought I’d post to let you know. The design and style look great though!
Hope you get the problem fixed soon. Kudos

28. That is the precise blog for anyone who desires to find out about this topic. You realize so much its nearly onerous to argue with you (not that I actually would need匟aHa). You positively put a new spin on a topic thats been written about for years. Nice stuff, just nice!

29. I抎 need to verify with you here. Which isn’t something I often do! I get pleasure from studying a put up that may make folks think. Also, thanks for permitting me to remark!

30. リラックスして自由に仕事をしていれば、最高の気分で作品に臨むことができるんだ。

31. It’s an amazing piece of writing in support of all the internet people;
they will get benefit from it I am sure.

32. Hi, after reading this amazing article i am
too glad to share my experience here with colleagues.

33. Really no matter if someone doesn’t understand afterward its
up to other users that they will assist, so here it takes place.

34. Appreciate the recommendation. Let me try it out.

35. Hurrah! Finally I got a website from where I be able to in fact take useful data
regarding my study and knowledge.

36. Hey just wanted to give you a brief heads up and let you know a few of the pictures aren’t loading correctly.
I’m not sure why but I think its a linking
issue. I’ve tried it in two different browsers and both show the same results.

37. Way cool! Some extremely valid points! I appreciate you writing this post and the rest of the site is very good.

38. Why so many people die in hospitals instead of at home | PBS NewsHour Why so many people die in hospitals instead of at home