• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
April 09, 2024 |330 Views
PROBLEM OF THE DAY : 08/04/2024 | Optimal Strategy For A Game
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Yash Dwivedi. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of DP but also build up problem-solving skills.

In this problem, we are given, an array arr of size n. The elements of the array represent n coin of values v1, v2, ....vn. You play against an opponent in an alternating way. In each turn, a player selects either the first or last coin from the row, removes it from the row permanently, and receives the value of the coin.
You need to determine the maximum possible amount of money you can win if you go first.
Note: Both the players are playing optimally.

Example :

Input:
n = 4
arr[] = {5, 3, 7, 10}
Output: 
15
Explanation: The user collects maximum value as 15(10 + 5). It is guarantee that we cannot get more than 15 by any possible moves.

Give the problem a try before going through the video. All the best!!!
Problem Link: https://www.geeksforgeeks.org/problems/optimal-strategy-for-a-game-1587115620/1
Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp14-compiler/2eb5b2fb-1010-49de-b489-0aeef72152db