Skip to content

Instantly share code, notes, and snippets.

@nachiketkanore
Created June 4, 2021 12:04
Show Gist options
  • Save nachiketkanore/271d1bd4587a14ad399acdef9bf10ddd to your computer and use it in GitHub Desktop.
Save nachiketkanore/271d1bd4587a14ad399acdef9bf10ddd to your computer and use it in GitHub Desktop.
int go(int i, int j) {
if (i == n || j == m) return 0;
int &ans = dp[i][j];
if (ans != -1) return ans;
ans = 0;
int c1 = 0;
if (s[i] == t[j]) {
c1 = 1 + go(i + 1, j + 1);
}
int c2 = 0 + go(i + 1, j);
int c3 = 0 + go(i, j + 1);
return ans = max({c1, c2, c3});
}
// max_length = go(0, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment