What is the error..it is giving adress as an output


Try solving with smaller value of N(N<5000) as it is O(N*N) solution.
You can check my code which works fine.I have used memoization rest logic is same as yours

i have run my code in the cb ide not here…issue is not tle but not giving correct output

why is it so if you know answer please

You are filling dp in the wrong way.
Fill the dp in sizes ie. For size 1,2 and so on
For size 2 say 1-2, 2-3,3-4 and so on values will be filled.
Similarly for 3, 1-3,2-5,3-6 and so on values will be filled.
Then apply the same logic it will work fine.