Querry regarding approach

Heyy, I’ve solved this using two pointers. But is there any way to solve it using dp too? similar problem is on codeforces also and the problem tag suggests that it can be solved using dp. Please tell how?

@Aparna
Actually when you are using two pointer approach it is sort of dp because you’re using precalculated result with the previous pointer. So the 2 pointer approach is begin referred to as DP only. Codeforces tends to do that. So the approach is same in both cases.

If your doubt is resolved please close it.

ohh, okayy thanks :smiley: //

1 Like

@Aparna
If you haven’t already the closed the doubt then please do so.