Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Python:- Write a function: int solution(int All, int N); that, given an array A consisting of N integers, returns the maximum sum of two

Using Python:-

Write a function: int solution(int All, int N); that, given an 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: 1. 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 pair sums up to 93.

2. 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 I 60 gives the result 102.

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

Write an efficient algorithm for the following assumptions: N is an integer within the range [1..200,000]; each element of array A is an integer within the range [1..1,000,000,000].

image text in transcribed

Write a function: int solution(int A[], int N ); that, given an 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: 1. 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 pair sums up to 93. 2. 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. 3. Given A=[51,32,43], the function should return 1, since all numbers in A have digits that add up to different, unique sums. Write an efficient algorithm for the following assumptions: - N is an integer within the range [1..200,000]; - each element of array A is an integer within the range Copyright 2009-2022 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

How do we organise for international logistics?

Answered: 1 week ago