Hackerearth problem - Even Odd Subarrays

Please help me with this question and I wanted a dp approach using recursion.

No dp required. It is a simple implementation problem. Replace all odd numbers with ‘1’ and even numbers with ‘-1’…now search on Google:-How to find the number of subarrays with sum=0,problem solved :slight_smile:

2 Likes

I got this solution, but since i am practicing dp and want solution of this problem in dp itself

I think you are not clear about what dp is. Its not recursion. + If you use recursion in this problem, you are bound to get TLE.

  • the last part which I mentioned,find the no.of subarrays with sum=0 comes under dp part only.
    This problem is under-dp-section, but it does not involve any/much dp.
    Try to find problems which involve dp.

I am sure there doea not exist any solution which passes the time limit using recursion here. Recursion is not at all needed here.

Please can you provide me the link where can i practice dp and strengthen it

I was actually telling to do it by recursion + memoization and thus reducing the running time