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

Function dfs

javascript/0312-burst-balloons.js:42–66  ·  view source on GitHub ↗
(nums, left, right, memo, result = 0)

Source from the content-addressed store, hash-verified

40 ); /* Time O(N) | Space O(N) */
41
42var dfs = (nums, left, right, memo, result = 0) => {
43 for (let i = left; i <= right; i++) {
44 /* Time O(N) */
45 const gain = nums[left - 1] * nums[i] * nums[right + 1];
46 const _left = search(
47 nums,
48 left,
49 i - 1,
50 memo,
51 ); /* Time O(N * N) | Space O(HEIGHT) */
52 const _right = search(
53 nums,
54 i + 1,
55 right,
56 memo,
57 ); /* Time O(N * N) | Space O(HEIGHT) */
58 const remaining = _left + _right;
59
60 result = Math.max(result, remaining + gain);
61 }
62
63 memo[left][right] =
64 result; /* | Space O(N * N) */
65 return result;
66};
67
68/**
69 * DP - Bottom Up

Callers 1

searchFunction · 0.70

Calls 1

searchFunction · 0.70

Tested by

no test coverage detected