Community

Start a Thread


Notifications
Subscribe You’re not receiving notifications from this thread.

Maximum Sum of Absolute Difference of Values and Indices (Main Thread)

Here is the interview question prompt, presented for reference.

The Puzzle in Simple Terms

You have a list of numbers called A. Your task is to pick two numbers from this list, let's call them A[i] and A[j]. Additionally, you will take note of their positions, i and j, in the list. You are to find the biggest result you can get from a specific formula.

The Formula to Understand

The formula is simple: You take the difference between the two numbers you picked and add it to the difference between their positions in the list. The trick here is to always consider the differences as positive numbers. We write this as:

The formula = |A[i] - A[j]| + |i - j|

The vertical bars mean we're taking the absolute value, so negative differences become positive.

Straightforward But Slow Way to Solve It

The most obvious way to solve this is to compare every pair of numbers in the list using the formula. But be warned! This can be very time-consuming if the list is long.

What's Next?

This problem may look simple, but solving it efficiently is where the challenge lies. To prepare for a software engineering career, learning how to solve such problems in a more efficient manner is crucial.

You can see the full challenge with visuals at this link.

Challenges • Asked almost 4 years ago by Jake from AlgoDaily

Jake from AlgoDaily Commented on Jul 28, 2020:

This is the main discussion thread generated for Maximum Sum of Absolute Difference of Values and Indices.