Few points you need to consider…
The problem statement considers even/odd place of number starting from the One’s place (one’s place being position 1).
In a typical digit DP problem, the numbers are formed such that numbers having lesser number of digits have preceding zeroes.
For example : If your limit is 1234 and a number 9 is formed in the recursion, it would look like 0009
So, do consider at which position the number actually starts building!
Here is my code, although it can be made more space efficient, I have taken a state called “realidx” to show the point 2.
Hope it helps.
There is a thread for users like you to ask questions. Please give a forum search. Converted to question nonetheless.