Jaydeep

Photo by Weston MacKinnon on Unsplash

Write a function given array A consisting of N integers, returns the maximum sum of two numbers whose digits add up to an equal sum. If there are no two numbers whose digits have an equal sum, the function should return -1.

Examples:

Given A =[51, 71, 17, 42], the function should return 93. There are two pairs of numbers whose digits add up to an equal sum: (51,42) and(17,71). The first pairs sums up to 93.

Given A =[42, 33, 60], the function should return 102. The digits of all numbers in A add up to the same sum, and choosing to add 42 and 60 gives the result 102.

Given A =[51, 32, 43], the function should return -1, since all numbers in A have digits that add up to different, unique sums

--

--

Jaydeep

Jaydeep

Full Stack Programmer, love to solve problem’s during free time.