2653. Check if There is a Path With Equal Number of 0's And 1's

Medium
Array
Dynamic Programming
Matrix

Description

Hints

Hint 1
Can you use dynamic programming to solve the problem?
Hint 2
Let dp[i][j][diff] be true if there is a path from the cell (i, j) to (m - 1, n - 1) such that the difference between the number of 0’s and the number of 1’s that we visited so far is diff, or false otherwise. The answer to the problem will be dp[0][0][0]. How do you compute this dp?

Statistics

Acceptance
51.7%
Submissions
14,680
Accepted
7,586