Increasing Triplet Subsequence LeetCode solution in JavaScript

1
var increasingTriplet = function (nums) {
2
const length = nums.length,
3
arr = [];
4
let tripletFound = false,
5
arrLength,
6
added = false,
7
found = false;
8
if (length < 3) return false;
9
arr.push([nums[0], 1]);
10
for (let index = 1; index < length; index++) {
11
let count = 1;
12
added = false;
13
found = false;
14
arrLength = arr.length;
15
for (let index2 = 0; index2 < arrLength; index2++) {
16
if (arr[index2][0] < nums[index]) {
17
added = true;
18
if (count !== arr[index2][1] + 1) {
19
count = arr[index2][1] + 1;
20
if (
21
JSON.stringify(arr[index2 + 1]) !==
22
JSON.stringify([nums[index], count])
23
)
24
arr.push([nums[index], count]);
25
}
26
if (arr[index2][1] + 1 === 3) {
27
tripletFound = true;
28
break;
29
}
30
}
31
if (arr[index2][0] === nums[index]) found = true;
32
}
33
if (tripletFound) break;
34
if (!added && !found) {
35
arr.push([nums[index], 1]);
36
}
37
}
38
return tripletFound;
39
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0