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

Function dfs

javascript/0494-target-sum.js:21–36  ·  view source on GitHub ↗
(nums, target, index, sum)

Source from the content-addressed store, hash-verified

19};
20
21var dfs = (nums, target, index, sum) => {
22 const left = findTargetSumWays(
23 nums,
24 target,
25 index + 1,
26 sum + nums[index],
27 ); /* Time O(2^N) | Space O(HEIGHT) */
28 const right = findTargetSumWays(
29 nums,
30 target,
31 index + 1,
32 sum - nums[index],
33 ); /* Time O(2^N) | Space O(HEIGHT) */
34
35 return left + right;
36};
37
38/**
39 * DP - Top Down

Callers 2

findTargetSumWaysFunction · 0.70
calculateFunction · 0.70

Calls 2

calculateFunction · 0.85
findTargetSumWaysFunction · 0.70

Tested by

no test coverage detected