Ques : ACODE

I am a beginner and I tried to solve this ques using DP .It shows correct results for the testcases not involving zeroes in between the i/p number.

For example)

It fails when i/p is:

310

(shows: 2,but ans should be: 1)

10110

(shows:6,but ans should be:1)

And on submission (when I hadn’t thought about the above test cases) shows TLE.

Please help!

My code:

```
#include <iostream>
#include <string.h>
#define ll long long
using namespace std;
ll l; //the size of i/p array
ll func(int *a, int s, int *dp)
{
//Base Case:
if (s >= l)
{
return 1;
}
//DP Case:
if (dp[s] != 0)
{
return dp[s];
}
//Recursive Case:
ll ans = 0;
if (s != l - 1)
{
int dig = a[s] * 10 + a[s + 1];
if (dig > 9 && dig <= 26)
{
ans += func(a, s + 2, dp);
dp[s] = ans;
}
}
ans += func(a, s + 1, dp);
dp[s] = ans;
return ans;
}
int main()
{
string n;
cin >> n;
while (n != "0")
{
l = n.size();
int *a = new int[l];
for (int i = 0; i < l; i++)
{
a[i] = n[i] - '0';
}
int *dp = new int[l]{0};
cout << func(a, 0, dp) << endl;
delete[] dp;
delete[] a;
cin >> n;
}
return 0;
}
```