What is difference between this and optimal game 1

Can you please tell that what is difference between the two as i got all test cases that are hidden failed.

main difference between both the question is that since Optimal-1 has array size of max 30 so in that question simple recursion without dp will give you All Test Case passed.
but since Optimal 2 has bigger array size using recursion without memoization will not be efficient so you need to use dp in second one while you don’t need dp in first one.
and if you are submitting same code from the first one atleast change the array size as per constraints of current problem.using dp array of size 50 will give you wrong answer for sure in second optimal problem.

I have applied Dp by using strg type 2 D array , still all test cases failed.

Statically allocating dp is too much for 1e4*1e4, you can use dynamic allocation by using vectors.
Check https://ide.codingblocks.com/s/381314

I have updated my code , Can you please update more ? https://ide.codingblocks.com/s/383764

don’t pass dp as an argument in the OptimalGame method. Keep it global.