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.
Examples
01 · Example 1
memory = [3, 4, 5] return = 26
🍒🍒
02 · Example 2
memory = [1, 2, 3] return = 14
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
🍓More Amazon problems
- Get the Fewest Moves (~Operations~)~Seen Jun 2026
- Create Array Generator ServiceSeen Jun 2026
- Minimum Merge ConflictsOA · Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Drone Delivery RouteOA · Seen Jun 2026
- Minimum Operations to Make Array ValidOA · Seen Jun 2026
- Sort Bug Report FrequenciesOA · Seen Jun 2026
- Maximum Equal Parts for PrefixesOA · Seen Jun 2026
public int maximizeMemoryPoints(int[] memory) {
// write your code here
}
memory[3, 4, 5]
expected26
sign in to submit