I recently came across an interview question, and am stuck solving it. Can someone help me with this.
The question goes like this -
There are two people (p1 and p2). They are playing a game, where an array with some values is given.
p1 makes the first turn, and p2 makes the 2nd turn, and this goes on.
p1 play optimally, i.e. it always plays to select those value from the array which makes his sum maximum. p1 can pick any of the available value from the array.
p2 does not play optimally. p2 simply picks the first available value (from the left).
In the end we have to tell the score obtained by p1, and p2.
Eg: ; Let say array is- [8,3,9,4,15,7]
So, for this case, ans will be: p1 score = 32, and p2 score = 14.
Explanation: p1 picks 1st value, p2 picks 2nd
then p1 picks 3rd, p2 picks 4th,
then p1 picks 5th, p2 picks 6th