Created
February 29, 2020 02:54
-
-
Save 100daysofdevops/26f4f4953ea97ecb6631dc33d187e4bd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def sum(num): | |
sum_val = 0 | |
while num: | |
sum_val += num % 10 | |
num //= 10 | |
return sum_val | |
def solution(A): | |
sum_map = {} | |
my_sum = -1 | |
for num in A: | |
digit_sum = sum(num) | |
if digit_sum in sum_map: | |
my_sum_val = sum_map[digit_sum] | |
my_sum = max(my_sum, my_sum_val + num) | |
sum_map[digit_sum] = max(my_sum_val, num) | |
else: | |
sum_map[digit_sum] = num | |
return my_sum | |
A = [42,33,60,199991,191999] | |
print(solution(A)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment