Longest Well-Performing Interval LeetCode solution in JavaScript

1
var longestWPI = function (hours) {
2
var dp = new Array(hours.length).fill(0);
3
for (i = 0; i < hours.length; i++) {
4
if (dp[i - 1] > 0 && hours[i] <= 8) {
5
dp[i] = dp[i - 1] - 1;
6
continue;
7
}
8
let tiring = 0;
9
for (j = i; j < hours.length; j++) {
10
if (hours[j] > 8) tiring++;
11
else tiring--;
12
if (tiring > 0) dp[i] = Math.max(dp[i], j - i + 1);
13
}
14
}
15
return Math.max(...dp);
16
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0