FastPrepFastPrep
Problem Brief

Maximize Memory Points (India Intern :)

INTERNFULLTIMEOA

The course has n chapters, each chapter has memory[i] memory points, which a student gains or loses while reading that chapter.

The course has a requirement: in order to study the ith chapter, the student must revisit all the previous chapters. A student gains memory[0] + memory[1] + ... + memory[i] memory points for reading the ith chapter. The total memory points is the sum of memory points gained while reading each chapter.

Students can read the chapters in any order, and want to maximize their total memory points. Find the maximum total memory points a student can score ensuring that all the chapters are read.

1Example 1

Input
memory = [3, 4, 5]
Output
26
Explanation
πŸ’πŸ’

2Example 2

Input
memory = [1, 2, 3]
Output
14
Explanation
The cumulative values are [1, 1 + 2, 1 + 2 + 3], which gives 1 + 3 + 6 = 10. The best arrangement is [3, 2, 1]: Step 1: 3 (cumulative sum = 3) Step 2: 3 + 2 = 5 (cumulative sum = 8) Step 3: 3 + 2 + 1 = 6 (cumulative sum = 14) Total sum: 3 + 5 + 6 = 14 :) POSSIBLE SOLUTION HINT (Just a probability; Accuracy cant be guaranteed πŸ₯° HHHHHappiiiiii 2025 new year! wish you happi coding!!)- Sorted the input array in descending order, then calculated the cumulative sums :)

Constraints

Limits and guarantees your solution can rely on.

πŸ“
public int maximizeMemoryPoints(int[] memory) {
  // write your code here
}
Input

memory

[3, 4, 5]

Output

26

Sign in to submit your solution.