please see my code.
π‘ Optimal Game Strategy-I
Actually both players will optimally and you forgot to maximize value for 2nd player or when bari = 0. Hence it was failing in this case:
4
8 15 3 7
Here is your modified code. In this code solve() is returning answer for player 1 when player 2 has played optimally for range [l ,r] and vice-versa.
PS: Because of small test cases the code will work but if there were huge test cases your code could have given TLE. You could have used DP to optimize it.
so you are maximizing the answer for opponent and finally subtracting it from total sum. Nice ! , Canβt we directly find the answer for Player 1.
I m not sure but may be maximizing first time and minimizing second time and so on.