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

Function linearSearch

javascript/0300-longest-increasing-subsequence.js:19–31  ·  view source on GitHub ↗
(nums, tabu)

Source from the content-addressed store, hash-verified

17const initTabu = (nums) => new Array(nums.length).fill(1);
18
19var linearSearch = (nums, tabu) => {
20 for (let right = 1; right < nums.length; right++) {
21 /* Time O(N) */
22 for (let left = 0; left < right; left++) {
23 /* Time O(N) */
24 const canUpdate = nums[left] < nums[right];
25 if (!canUpdate) continue;
26
27 const [_left, _right] = [tabu[left] + 1, tabu[right]];
28 tabu[right] = Math.max(_right, _left); /* Space O(N) */
29 }
30 }
31};
32
33/**
34 * Array - Subsequence

Callers 1

lengthOfLISFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected