FastPrepMaximize Memory Points
Problems/Maximize Memory Points

Maximize Memory Points

Amazon logoAmazon● MediumINTERNFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

A course has n chapters. Chapter i has memory[i] memory points. A student gains these points while reading the chapter, or loses them if the value is negative.

The course has one rule: to study a chapter, the student must first revisit all the chapters read before it. So the k-th chapter you read gives the sum of the memory points of the first k chapters you read. The total memory points is the sum of the points from every chapter.

You can read the chapters in any order, but you must read all of them. Return the largest total memory points you can get.

Function

maximizeMemoryPoints(memory: int[]) → int

Complete the function maximizeMemoryPoints in the editor.

maximizeMemoryPoints has the following parameter:

  • int memory[n]: the memory points of each chapter

Returns int: the largest total memory points

Examples

Example 1

memory = [3, 4, 5]return = 26

Read the chapters in the order 5, 4, 3. Reading 5 gives 5 points. Reading 4 next gives 5 + 4 = 9. Reading 3 last gives 5 + 4 + 3 = 12. The total is 5 + 9 + 12 = 26. The first chapter you read is counted 3 times, the second twice and the last once, so the largest value should go first. The answer is 26.

Example 2

memory = [1, 2, 3]return = 14

In the given order 1, 2, 3, the running sums are 1, 1 + 2 = 3 and 1 + 2 + 3 = 6, for a total of 10. The order 3, 2, 1 is better. Its running sums are 3, 3 + 2 = 5 and 3 + 2 + 1 = 6, for a total of 3 + 5 + 6 = 14. The first chapter you read is counted 3 times, the second twice and the last once, so the largest value should go first. The answer is 14.

Constraints

  • 1 <= n <= 2000, where n is the length of memory
  • -1000 <= memory[i] <= 1000

More Amazon interview questions

  • Add Course Batches All or NothingONSITE INTERVIEW · Seen Dec 2026
  • Priority Ad Rotation with Show LimitsONSITE INTERVIEW · Seen Dec 2026
  • Next Greater Element IONSITE INTERVIEW · Seen Dec 2026
  • Count Connected ComponentsPHONE SCREEN · Seen Dec 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Merge Accounts by Shared AttributePHONE SCREEN · Seen Dec 2026
  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Minimum Grid InconvenienceOA · Seen Dec 2026
  • Optimal Account BalancingONSITE INTERVIEW · Seen Dec 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026

Similar questions at other companies

  • Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
  • Minimum Cost of Every K-Capable Model SetTikTok · OATikTok interview questions
  • K-Capable Model SelectionWalmart · OAWalmart interview questions
  • Call Auction Clearing Price and Order FillsHudson River Trading · PHONE SCREENHudson River Trading interview questions
  • Subscription and Usage-Based Billing CalculatorStripe · OAStripe interview questions
  • Count Lamps Lighting Each PointAirbnb · OAAirbnb interview questions
  • Hiking Club Fastest PaceInfosys · OAInfosys interview questions
  • Find Minimum TimeAlphaSense · OA
  • Find Minimum TimeBlackRock · OABlackRock interview questions
  • Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions

Interview reports that mention this question

  • Amazon Intern OA Problems: Every Task We Have (Part 2 of 5)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int maximizeMemoryPoints(int[] memory) {
      // write your code here
    }

}
Checking account…