shashwat_nayak's blog

By shashwat_nayak, history, 20 months ago, In English

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.

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it