Maximum Sum of Two Numbers (Microsoft Online Onsite Interview-Codility platform)

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

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

@Pay: Development Updates

Engineering Guiding Principles

6 main digital transformation advantages you can achieve with low-code development

6 digital transformation benefits of low-code development

DEBUG CODE — A Developer Blogging Website

Useful technologies to use when writing software

Git — First Time? This is For You! Start Your First Project in GitHub

Niagara Pro’s Swipe Actions

How we’re Making Tax Digital at FreeAgent

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jaydeep

Jaydeep

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

More from Medium

Cracking the system design interview

LeetCode: Top K Frequent Elements

One interview, Many learnings

Design Underground System