Optimal Score Difference in an Endpoint Game
Updated
Problem statement
Two players alternately remove either the first or the last number from nums until the array is empty. A removed number is added to that player's score. The first player moves first.
Both players play optimally to maximize their own final score. Return the first player's score minus the second player's score. The answer may be negative.
Function
maximumScoreDifference(nums: int[]) → intExamples
Example 1
nums = [1,5,2]return = -2The first player can collect 3 while the second collects 5, giving -2.
Example 2
nums = [4,7,2,9]return = 10The first player can secure 16 while the second collects 6, giving 10.
Constraints
1 <= nums.length <= 1000.-10^6 <= nums[i] <= 10^6.
More Rippling Online Assessment questions
- Most Segments That Sort the ArrayOA · Seen Nov 2026
- Palindromic Paths to the RootOA · Seen Nov 2026
- Server InvestmentOA · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- REST API: Highest International StudentsOA · Seen Sep 2026
- Token ValidationOA · Seen Sep 2026
- Consistent LogsOA · Seen Sep 2026
- Costliest ChocolateOA · Seen Sep 2026
- Server ManagementOA · Seen Sep 2026
- Cyber Beacon DetectionOA · Seen Aug 2026
Similar questions at other companies
- Card Game: Best First-Player ScoreShopify · OAShopify interview questions
- Maximum Game Score with Fixed Forward JumpsStripe · OAStripe interview questions
- 0/1 KnapsackConfluent · OAConfluent interview questions
- Minimum Cost to Tile a Strip with Widths 1, 2, and 3Infosys · OAInfosys interview questions
- Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
- Maximum Subarray SumStraive · OA
- Longest Increasing Price SubsequenceOpenAI · OAOpenAI interview questions
- Lowest-Cost Shirt Color ScheduleElevenLabs · OAElevenLabs interview questions
- Maximum Game Board ScoreJP Morgan Chase · OAJP Morgan Chase interview questions
- API Bandwidth AllocationArista Networks · OAArista Networks interview questions