Maximal Square leetcode dp

Revision en1, by shashwat_nayak, 2022-09-03 19:35:42

Hi, I was solving this dp question (Maximal square from leetcode).

Question LINK

Let a be the input array.
The correct recurrence relation goes like:
dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1

Correct code

But i was doing something like:
int val=min(dp[i - 1][j], dp[i][j - 1])
if(a[i-val][j-val]==1)dp[i][j] = val+ 1

This relation is incorrect but i was not able to find a testcase where it is failing.

My code

Can anyone point out a testcase where it fails.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English shashwat_nayak 2022-09-03 19:35:42 2737 Initial revision (published)