Anishluke92 / RubySolution

Problem solving using Ruby programming language
0 stars 1 forks source link

Coin selection game #75

Open danielpaul opened 3 years ago

danielpaul commented 3 years ago

This problem was asked by Square.

In front of you is a row of N coins, with values v1, v1, ..., vn.

You are asked to play the following game. You and an opponent take turns choosing either the first or last coin from the row, removing it from the row, and receiving the value of the coin.

Write a program that returns the maximum amount of money you can win with certainty, if you move first, assuming your opponent plays optimally.