Maximize Total Memory Points
Learn this problemProblem statement
FastPrep.io Academy has recently introduced an exciting new course focused on Quantum Physics, providing learners with an opportunity to explore the fascinating world of quantum mechanics and its applications.
The course has n chapters, where the i-th chapter has memory[i] memory points, which a student gains or loses while reading that chapter. The course follows a specific requirement: before studying a chapter, the student must revisit all the previously read chapters.
This means that when reading the chapter placed at position i in the chosen reading order, the student accumulates a total of memory[0] + memory[1] + ... + memory[i] memory points, where the indices refer to the chapters in the order chosen by the student. The total memory points is the sum of the memory points gained while reading each chapter.
Students have the flexibility to read the chapters in any order and aim to maximize their total memory points. The goal is to determine the maximum possible total memory points a student can accumulate while ensuring that all chapters are read at least once.
Your task is to find and return the highest possible total memory points that a student can achieve by choosing the optimal reading order.
Function
maximizeTotalMemoryPoints(memory: int[]) → longExamples
Example 1
memory = [3, 4, 5]return = 26Constraints
1 ≤ n ≤ 10^5-10^3 ≤ memory[i] ≤ 10^3
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026