MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / dfs

Function dfs

javascript/0115-distinct-subsequences.js:35–58  ·  view source on GitHub ↗
(s, t, i, j, memo)

Source from the content-addressed store, hash-verified

33 new Array(s.length).fill().map(() => new Array(t.length).fill(null));
34
35var dfs = (s, t, i, j, memo) => {
36 const left = numDistinct(
37 s,
38 t,
39 i + 1,
40 j,
41 memo,
42 ); /* Time O(N * M) | Space O(HEIGHT) */
43
44 const isEqual = s[i] === t[j];
45
46 const right = isEqual
47 ? numDistinct(
48 s,
49 t,
50 i + 1,
51 j + 1,
52 memo,
53 ) /* Time O(N * M) | Space O(HEIGHT) */
54 : 0;
55
56 memo[i][j] = left + right; /* | Space O(N * M) */
57 return memo[i][j];
58};
59
60/**
61 * DP - Bottom Up

Callers 1

numDistinctFunction · 0.70

Calls 1

numDistinctFunction · 0.70

Tested by

no test coverage detected