1399. Take Coins
There are
n coins in a row, each time you want to take a coin from the left or the right side. Take a total of k times to write an algorithm to maximize the value of coins.
Have you met this question in a real interview?
Example
Given list =
[5,4,3,2,1], k = 2, return 9.Explanation:
Take two coins from the left.
Given list =
[5,4,3,2,1,6], k = 3, return 15.Explanation:
Take two coins from the left and one from the right.
Comments
Post a Comment