Dsa
Dynamic Programming
Medium
Optimal Game Strategy
Two players play a game with piles of coins arranged in a line. Each player can take coins from either end of the line. The goal is to maximize the number of coins a player can collect. Given an array of integers representing the number of coins in each pile, write a function that returns the maximum number of coins that the first player can secure with optimal play from both sides.
Input format:
- The first line contains an integer n, the number of piles.
- The second line contains n space-separated integers representing the piles.
Output format:
- A single integer representing the maximum number of coins the first player can collect.
Example:
Input:
4
8 15 3 7
Output:
22
Key concepts
dynamic_programminggame_theory
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now