Hello Codeforces community!

Problem Link : Link

I have a memoized solution for this problem. The issue here is that my complexity is : O(N^3), which leads me to TLE. All the editorials and blogs I have seen have used Bottom up approach and suffix sum to get it to O(N^2). But I'm not sure how to translate this idea to the memoized version.

```
int dpSol(int i, int level)
{
if(i == n - 1)
return 1;
if(cache[i][level] != -1)
return cache[i][level];
if(arr[i] == 's')
{
int sum = 0;
for(int j = 0; j <= level; ++j)
sum = (sum + dpSol(i + 1, j)) % MOD;
return cache[i][level] = sum;
}
return cache[i][level] = dpSol(i + 1, level + 1);
}
```

Any help will be appreciated! Thanks in advance.

Can you link the problem?

Sorry, I have updated my question. Link : https://codeforces.com/problemset/problem/909/C

You can't do it easily with recursion. Some people did it but it was quite hard to explain compared with the bottom up solution. If you still want the recursion solution see: 33679063

I have the Same problem... https://codeforces.com/contest/909/submission/55870468 I didn't get how to apply prefix sum.