Coin Game Problem Statement

Wong wants to borrow money from Dr. Strange, who insists Wong must win a coin game first. The game involves two players taking turns to remove one coin from either end of a row of coins arranged by Dr. Strange. Each coin has a value, and the player with the highest total value in the end wins. Wong plays first and seeks to win with your help.

Objective

Given an array of integers, ARR, with each integer representing the value of a coin, determine the maximum value Wong can obtain by following these rules:

  1. Players alternate turns and may remove one coin from either end of the array.
  2. Once a coin is removed, it cannot be replaced.

Example:

Input:
T = 2
N = 3
ARR = [10, 20, 30]
N = 1
ARR = [100]
Output:
40
100
Explanation:

In the first test case: Wong can remove 30, Dr. Strange removes 20, and Wong removes 10. Wong's total is 40, and he wins.

In the second test case: Wong removes the sole coin of value 100 and wins immediately.

Constraints:

  • 1 ≤ T ≤ 5
  • 1 ≤ N ≤ 10^3
  • 1 ≤ ARR[i] ≤ 10^7 where 'ARR[i]' denotes the coin value at the ith position in the array.

Note:

The game ends when no coins are left. If the game is a draw, Wong is considered the winner.

AnswerBot
4mo

Given an array of coin values, determine the maximum value Wong can obtain by playing a coin game against Dr. Strange.

  • Wong plays first and can remove one coin from either end of the array on each turn...read more

Help your peers!
Select
Add answer anonymously...

DE Shaw Software Developer interview questions & answers

A Software Developer was asked 12mo agoQ. Given a binary tree and a target node, burn the tree starting from the target no...read more
A Software Developer was asked Q. What is the purpose of Normalization?
A Software Developer was asked Q. What is the difference between a default constructor and a copy constructor?

Popular interview questions of Software Developer

A Software Developer was asked 12mo agoQ1. Given a binary tree and a target node, burn the tree starting from the target no...read more
A Software Developer was asked Q2. What is the purpose of Normalization?
A Software Developer was asked Q3. What is the difference between a default constructor and a copy constructor?
DE Shaw Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits