US · interviewqs.com

Calculating max distance between array elements in Python

Python, Data Structures, Arrays,


This email was sent

Is this your brand on Milled? Claim it.

InterviewQs

Calculating max distance between array elements in Python

Python Data Structures Arrays

Forward this email to a friend or colleague and challenge them to solve it.

Hi, 

Suppose you are given an array of length n. Choose i numbers in the array such that the absolute difference between the sum of your numbers and the sum of remaining numbers is as large as possible. Your function should return the max possible distance between the two sets of numbers.

For example:

    

#Given the following:

arr[ ] = [2, 4, 3, 1, 10]

i = 2

Output: 14

Here, we chose #s 1,2 and the sum of the remaining #s (4,3,10) is 17. Therefore, our output is 17 - 3 = 14.


 

You’ve accumulated 155 questions since joining our email list. Create a premium account to access detailed solutions to each problem (including this one) + our new Case studies.


Was this email forwarded to you? You can join our list here to receive questions

How did you like today's question?

15411 Boischatel, Montreal, QC, H9H1Y7, Canada
Don't want to get these emails anymore? We'll forgive you if you unsubscribe
Are you sure?

Lists help you organize the brands that you care about. Your lists are private to you.