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

Function longestConsecutive

javascript/0128-longest-consecutive-sequence.js:9–24  ·  view source on GitHub ↗
(nums, maxScore = 0)

Source from the content-addressed store, hash-verified

7 * @return {number}
8 */
9var longestConsecutive = (nums, maxScore = 0) => {
10 for (const num of nums) {
11 /* Time O(N) */
12 let [currNum, score] = [num, 1];
13
14 while (isStreak(nums, currNum + 1)) {
15 /* Time O(N * N) */
16 currNum++;
17 score++;
18 }
19
20 maxScore = Math.max(maxScore, score);
21 }
22
23 return maxScore;
24};
25
26const isStreak = (nums, num) => {
27 for (let i = 0; i < nums.length; i++) {

Callers

nothing calls this directly

Calls 2

isStreakFunction · 0.85
searchFunction · 0.70

Tested by

no test coverage detected