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

Function search

javascript/1143-longest-common-subsequence.js:94–104  ·  view source on GitHub ↗
(text1, text2, tabu)

Source from the content-addressed store, hash-verified

92 .map(() => new Array((text2.length + 1)).fill(0));/* Time O(M) | Space O(M) */
93
94var search = (text1, text2, tabu) => {
95 const [ n, m ] = [ text1.length, text2.length ];
96
97 for (let x = (n - 1); (0 <= x); x--) {/* Time O(N) */
98 for (let y = (m - 1); (0 <= y); y--) {/* Time O(M) */
99 tabu[x][y] = (text1[x] === text2[y]) /* Space O(N * M) */
100 ? (tabu[x + 1][y + 1] + 1)
101 : Math.max(tabu[x + 1][y], tabu[x][y + 1]);
102 }
103 }
104}
105
106/**
107 * DP - Bottom Up

Callers 1

longestCommonSubsequenceFunction · 0.70

Calls 1

initTabuFunction · 0.70

Tested by

no test coverage detected