Skip to content

Instantly share code, notes, and snippets.

@100daysofdevops
Created February 29, 2020 02:54
Show Gist options
  • Save 100daysofdevops/26f4f4953ea97ecb6631dc33d187e4bd to your computer and use it in GitHub Desktop.
Save 100daysofdevops/26f4f4953ea97ecb6631dc33d187e4bd to your computer and use it in GitHub Desktop.
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