-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e04533
commit 4b7bc13
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |