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

Function dfs

javascript/0097-interleaving-string.js:20–44  ·  view source on GitHub ↗
(s1, s2, s3, i, j, res, ans = false)

Source from the content-addressed store, hash-verified

18};
19
20var dfs = (s1, s2, s3, i, j, res, ans = false) => {
21 const hasLeft = i < s1.length;
22 if (hasLeft)
23 ans |= isInterleave(
24 s1,
25 s2,
26 s3,
27 i + 1,
28 j,
29 `${res}${s1[i]}`,
30 ); /* Time O(2^(N + M)) | Space O(N) */
31
32 const hasRight = j < s2.length;
33 if (hasRight)
34 ans |= isInterleave(
35 s1,
36 s2,
37 s3,
38 i,
39 j + 1,
40 `${res}${s2[j]}`,
41 ); /* Time O(2^(N + M)) | Space O(M) */
42
43 return ans;
44};
45
46/**
47 * DP - Top Down

Callers 1

isInterleaveFunction · 0.70

Calls 1

isInterleaveFunction · 0.70

Tested by

no test coverage detected