Calculating max distance between array elements in Python

Calculating max distance between array elements in Python
Python Data Structures Arrays

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.





Want the solutions? Upgrade to premium to access detailed solutions to each problem (including this one).

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


Unsubscribe

Older messages

Plotting stock prices

Saturday, February 13, 2021

Data Interview Qs Plotting stock prices Data Analysis Python Pandas External Dataset Matplotlib Using Python, create a line chart with both the daily and 7-day moving average for the close price for

Pricing a life insurance product

Monday, February 8, 2021

Data Interview Qs Pricing a life insurance product Statistics Probability Theory Expected Value Suppose you're working for a life insurance company that is trying to price a one year policy for a

Triplets that sum to zero

Friday, February 5, 2021

Data Interview Qs Triplets that sum to zero Python Data Structures Arrays Given an array of n distinct elements, can you find all the triplet combinations that sum to zero? For example: Input: [0, -1,

In SQL, 0 = 0?

Wednesday, February 3, 2021

Data Interview Qs In SQL, null = null? SQL Database Querying In SQL, what will be the result of the below query? select case when null = null then 'Yes' else 'No' end as Result; Want

Normalizing student grades against median

Monday, February 1, 2021

Data Interview Qs Normalizing student grades against median Data Analysis Python Pandas Data Manipulation Normalization You are given a dataframe containing student information, named df (shown below).

You Might Also Like

This Week's Daily Tip Roundup

Sunday, May 19, 2024

Missed some of this week's tips? No problem. We've compiled all of them here in one convenient place for you to enjoy. Happy learning! iPhoneLife Logo View In Browser Your Tip of the Day is

Reading Beyond the Hype: Some Observations About OpenAI and Google’s Announcements

Sunday, May 19, 2024

Google vs. OpenAI is shaping up as one of the biggest rivarly of the generative AI era. ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏

Final Reminder: Apple Issues "Update Now Warning"

Sunday, May 19, 2024

I wanted to send a final reminder — if you haven't already updated your iPhone to iOS 17.5, we strongly recommend you do so today. This is also your last chance to get access to our iOS 17.5 In-

Second Brain/Attention/Find Your Books

Sunday, May 19, 2024

Recomendo - issue #411 ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏

Kotlin Weekly #407

Sunday, May 19, 2024

ISSUE #407 19th of May 2024 Hello Kotliners! The Google I/O just finished this week with a huge announcement for us, with Google supporting now Kotlin Multiplatform on Android, and the KotlinConf will

Learn How to Use AI to Reach Your Full Potential, newsletterest1!

Sunday, May 19, 2024

3 Ways AI Can Help Your Writing ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌ ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌ ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌ ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌  ͏ ‌

Software Testing Weekly - Issue 220

Saturday, May 18, 2024

Software Testing Conferences 📚 View on the Web Archives ISSUE 220 May 18th 2024 COMMENT Welcome to the 220th issue! Have you ever been to a testing conference? They're a great way to learn about

📶 Is a Cellular iPad Worth It? — How to Prevent YouTube From Taking Over Your Screensaver

Saturday, May 18, 2024

Also: This Robot Vacuum Can Clean Stairs, and More! How-To Geek Logo May 18, 2024 📩 Get expert reviews, the hottest deals, how-to's, breaking news, and more delivered directly to your inbox by

Weekend Reading — Objection-oriented programming

Saturday, May 18, 2024

This week we find a power-up box, replace GitHub Actions with Maven XMLs, avoid the worst website in the world, revisit RTO policies, “listen” to OpenAI employees, watch our Slack private messages, do

Daily Coding Problem: Problem #1445 [Easy]

Saturday, May 18, 2024

Daily Coding Problem Good morning! Here's your coding interview problem for today. This problem was asked by Jane Street. The United States uses the imperial system of weights and measures, which