Skip to content

Commit 86385b1

Browse files
author
Amogh Singhal
authored
Create gen_largest_num_frm_list.py
1 parent eeb8824 commit 86385b1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

gen_largest_num_frm_list.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Write a function that given a list of non
2+
# negative integers, arranges them such that
3+
# they form the largest possible number. For
4+
# example, given [50, 2, 1, 9], the largest
5+
# formed number is 95021
6+
7+
from itertools import permutations
8+
9+
def generate_largest_number(arr):
10+
gen_nums = []
11+
for i in permutations(arr, len(arr)):
12+
gen_nums.append("".join(map(str, i)))
13+
return max(gen_nums)
14+
15+
arr = [54, 546, 548, 60]
16+
generate_largest_number(arr)

0 commit comments

Comments
 (0)