Please help me in SPOJ- Ra One

Can’t ask question as not having enough karma, can someone help in finding what’s wrong with this(Digit DP)
code ? Here is the problem statement.


1 Like

There is a thread for users like you to ask questions. Please give a forum search. Converted to question nonetheless.

Few points you need to consider…

  1. The problem statement considers even/odd place of number starting from the One’s place (one’s place being position 1).

  2. 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. :slight_smile:


1 Like