Calculating max distance between array elements in Python

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.


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.


 

Update: You’ve accumulated 134 questions since joining our email list. Create a premium account 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

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

Older messages

User Churn

Monday, May 10, 2021

SQL, Database Querying, InterviewQs User Churn SQL Database Querying Forward this email to a friend or colleague and challenge them to solve it. You're given a table called userActivityLogs. This

Plotting stock prices

Friday, May 7, 2021

Data Analysis, Python, Pandas, External Dataset, Matplotlib, InterviewQs Plotting stock prices Data Analysis Python Pandas External Dataset Matplotlib Forward this email to a friend or colleague and

Pricing a life insurance product

Wednesday, May 5, 2021

Statistics, Probability Theory, Expected Value, InterviewQs Pricing a life insurance product Statistics Probability Theory Expected Value Update: You've accumulated 131 questions in your account.

In SQL, 0 = 0?

Friday, April 30, 2021

SQL, Database Querying, InterviewQs In SQL, 0 = 0? 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

Normalizing student grades against median

Wednesday, April 28, 2021

Data Analysis, Python, Pandas, Data Manipulation, Normalization, InterviewQs Normalizing student grades against median Data Analysis Python Pandas Data Manipulation Normalization You are given a

You Might Also Like

Learning about Android Runtime

Thursday, April 25, 2024

View in browser 🔖 Articles Learning about Android Runtime I always enjoy reading articles that explore how something works under the hood. Here's an article that does exactly that, providing

Stripe changes its … stripes

Wednesday, April 24, 2024

TikTok on the president's docket and Nvidia acquires Run:ai View this email online in your browser By Christine Hall Wednesday, April 24, 2024 Good afternoon, and welcome to TechCrunch PM! Today

💪 You Can Use Copilot AI as a Personal Trainer — Why Your Laptop Needs a Docking Station

Wednesday, April 24, 2024

Also: Here's How to Make Your Apple ID Recoverable, and More! How-To Geek Logo April 24, 2024 📩 Get expert reviews, the hottest deals, how-to's, breaking news, and more delivered directly to

JSK Daily for Apr 24, 2024

Wednesday, April 24, 2024

JSK Daily for Apr 24, 2024 View this email in your browser A community curated daily e-mail of JavaScript news JSK Weekly - 24th April, 2024 React 19 has introduced many great functionalities and

Daily Coding Problem: Problem #1422 [Hard]

Wednesday, April 24, 2024

Daily Coding Problem Good morning! Here's your coding interview problem for today. This problem was asked by Airbnb. Given a list of integers, write a function that returns the largest sum of non-

Charted | Artificial Intelligence Patents, by Country 🤖

Wednesday, April 24, 2024

This visualization shows which countries have been granted the most AI patents each year, from 2012 to 2022. View Online | Subscribe Presented by: New on VC+: Our Visual Briefing on the IMF's World

Save your seat: 1Password’s 2024 Security report insights webinar

Wednesday, April 24, 2024

Join us April 25th. ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏

Top Tech Deals 📱 LG Flex TV, Google Pixel 7, DJI Mini 3, and More

Wednesday, April 24, 2024

Get yourself a discounted DJI drone, save on the Pixel 7, or score some PC and phone accessories. How-To Geek Logo April 24, 2024 Top Tech Deals: LG Flex TV, Google Pixel 7, DJI Mini 3, and More Find

The Protest Song Wakes Up 🎙️

Wednesday, April 24, 2024

Is this song the future of musical protest? Here's a version for your browser. Hunting for the end of the long tail • April 24, 2024 The Protest Song Wakes Up A buzzy protest song about the

JSK Weekly - 24th April, 2024

Wednesday, April 24, 2024

React 19 has introduced many great functionalities and features, among which the useOptimistic hook stands out. The useOptimistic hook offers a seamless way to manage UI states during asynchronous