Skip to content

Commit

Permalink
Add solution to Problem 228
Browse files Browse the repository at this point in the history
  • Loading branch information
vineetjohn committed Nov 2, 2018
1 parent 5e04533 commit 4b7bc13
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions solutions/problem_228.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
def get_largest(nums, prefix=""):
num_dict = dict()
for num in nums:
str_num = str(num)
fdig = str_num[0]
if fdig not in num_dict:
num_dict[fdig] = list()
num_dict[fdig].append(str_num)

sorted_arrs = sorted(num_dict.values(), key=lambda x: x[0], reverse=True)
combined = list()
for arr in sorted_arrs:
if len(arr) == 1:
combined.extend(arr)
continue

split_dict = dict()
for num in arr:
len_num = len(num)
if len_num not in split_dict:
split_dict[len_num] = list()
split_dict[len_num].append(num)

sorted_val_arrs = sorted(
split_dict.values(), key=lambda x: len(x[0]))
for val_arr in sorted_val_arrs:
combined.extend(sorted(val_arr, reverse=True))

return int(prefix.join(combined))


# Tests
assert get_largest([10, 7, 76, 415]) == 77641510

0 comments on commit 4b7bc13

Please sign in to comment.