File tree 2 files changed +48
-1
lines changed
2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,482 LeetCode solutions in JavaScript
1
+ # 1,483 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1307
1307
1691|[ Maximum Height by Stacking Cuboids] ( ./solutions/1691-maximum-height-by-stacking-cuboids.js ) |Hard|
1308
1308
1694|[ Reformat Phone Number] ( ./solutions/1694-reformat-phone-number.js ) |Easy|
1309
1309
1695|[ Maximum Erasure Value] ( ./solutions/1695-maximum-erasure-value.js ) |Medium|
1310
+ 1696|[ Jump Game VI] ( ./solutions/1696-jump-game-vi.js ) |Medium|
1310
1311
1716|[ Calculate Money in Leetcode Bank] ( ./solutions/1716-calculate-money-in-leetcode-bank.js ) |Easy|
1311
1312
1718|[ Construct the Lexicographically Largest Valid Sequence] ( ./solutions/1718-construct-the-lexicographically-largest-valid-sequence.js ) |Medium|
1312
1313
1726|[ Tuple with Same Product] ( ./solutions/1726-tuple-with-same-product.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1696. Jump Game VI
3
+ * https://leetcode.com/problems/jump-game-vi/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given a 0-indexed integer array nums and an integer k.
7
+ *
8
+ * You are initially standing at index 0. In one move, you can jump at most k steps forward without
9
+ * going outside the boundaries of the array. That is, you can jump from index i to any index in
10
+ * the range [i + 1, min(n - 1, i + k)] inclusive.
11
+ *
12
+ * You want to reach the last index of the array (index n - 1). Your score is the sum of all
13
+ * nums[j] for each index j you visited in the array.
14
+ *
15
+ * Return the maximum score you can get.
16
+ */
17
+
18
+ /**
19
+ * @param {number[] } nums
20
+ * @param {number } k
21
+ * @return {number }
22
+ */
23
+ var maxResult = function ( nums , k ) {
24
+ const n = nums . length ;
25
+ const maxScores = new Array ( n ) . fill ( - Infinity ) ;
26
+ const deque = [ ] ;
27
+
28
+ maxScores [ 0 ] = nums [ 0 ] ;
29
+ deque . push ( 0 ) ;
30
+
31
+ for ( let i = 1 ; i < n ; i ++ ) {
32
+ while ( deque . length && deque [ 0 ] < i - k ) {
33
+ deque . shift ( ) ;
34
+ }
35
+
36
+ maxScores [ i ] = nums [ i ] + maxScores [ deque [ 0 ] ] ;
37
+
38
+ while ( deque . length && maxScores [ i ] >= maxScores [ deque [ deque . length - 1 ] ] ) {
39
+ deque . pop ( ) ;
40
+ }
41
+
42
+ deque . push ( i ) ;
43
+ }
44
+
45
+ return maxScores [ n - 1 ] ;
46
+ } ;
You can’t perform that action at this time.
0 commit comments