recurse(i, j)
that takes indices i
and j
as arguments.j
is equal to the length of t
, return 1 (base case).i
is equal to the length of s
, return 0 (base case).recurse(i, j)
is already in the memoization dictionary. If yes, return the cached result.s[i]
matches t[j]
, recursively call recurse(i + 1, j + 1)
to move both pointers forward and add the result to recurse(i + 1, j)
where only the i
pointer is moved.s[i]
does not match t[j]
, recursively call recurse(i + 1, j)
.recurse(0, 0)
to start the recursion with both pointers at the beginning of s
and t
.