Mark As Completed Discussion

Good evening! Here's our prompt for today.

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:

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

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

Description

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.

Try to solve this here or in Interactive Mode.

How do I practice this challenge?

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

We'll now take you through what you need to know.

How do I use this guide?