File tree 2 files changed +44
-1
lines changed
2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,141 LeetCode solutions in JavaScript
1
+ # 1,142 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
887
887
1111|[ Maximum Nesting Depth of Two Valid Parentheses Strings] ( ./solutions/1111-maximum-nesting-depth-of-two-valid-parentheses-strings.js ) |Medium|
888
888
1122|[ Relative Sort Array] ( ./solutions/1122-relative-sort-array.js ) |Easy|
889
889
1123|[ Lowest Common Ancestor of Deepest Leaves] ( ./solutions/1123-lowest-common-ancestor-of-deepest-leaves.js ) |Medium|
890
+ 1124|[ Longest Well-Performing Interval] ( ./solutions/1124-longest-well-performing-interval.js ) |Medium|
890
891
1137|[ N-th Tribonacci Number] ( ./solutions/1137-n-th-tribonacci-number.js ) |Easy|
891
892
1143|[ Longest Common Subsequence] ( ./solutions/1143-longest-common-subsequence.js ) |Medium|
892
893
1161|[ Maximum Level Sum of a Binary Tree] ( ./solutions/1161-maximum-level-sum-of-a-binary-tree.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1124. Longest Well-Performing Interval
3
+ * https://leetcode.com/problems/longest-well-performing-interval/
4
+ * Difficulty: Medium
5
+ *
6
+ * We are given hours, a list of the number of hours worked per day for a given employee.
7
+ *
8
+ * A day is considered to be a tiring day if and only if the number of hours worked is
9
+ * (strictly) greater than 8.
10
+ *
11
+ * A well-performing interval is an interval of days for which the number of tiring days
12
+ * is strictly larger than the number of non-tiring days.
13
+ *
14
+ * Return the length of the longest well-performing interval.
15
+ */
16
+
17
+ /**
18
+ * @param {number[] } hours
19
+ * @return {number }
20
+ */
21
+ var longestWPI = function ( hours ) {
22
+ let result = 0 ;
23
+ let score = 0 ;
24
+ const seen = new Map ( ) ;
25
+
26
+ for ( let i = 0 ; i < hours . length ; i ++ ) {
27
+ score += hours [ i ] > 8 ? 1 : - 1 ;
28
+
29
+ if ( score > 0 ) {
30
+ result = i + 1 ;
31
+ } else {
32
+ if ( ! seen . has ( score ) ) {
33
+ seen . set ( score , i ) ;
34
+ }
35
+ if ( seen . has ( score - 1 ) ) {
36
+ result = Math . max ( result , i - seen . get ( score - 1 ) ) ;
37
+ }
38
+ }
39
+ }
40
+
41
+ return result ;
42
+ } ;
You can’t perform that action at this time.
0 commit comments