Skip to content

Commit c602acf

Browse files
authored
Create 1708-largest-subarray-length-k.js
1 parent 882cb7c commit c602acf

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

1708-largest-subarray-length-k.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {number[]} nums
3+
* @param {number} k
4+
* @return {number[]}
5+
*/
6+
const largestSubarray = function(nums, k) {
7+
const n = nums.length
8+
const hi = n - k
9+
let start = Number.MIN_VALUE, idx = -1
10+
for(let i = 0; i <= hi; i++) {
11+
if(nums[i] > start) {
12+
start = nums[i]
13+
idx = i
14+
}
15+
}
16+
return nums.slice(idx, idx + k)
17+
};

0 commit comments

Comments
 (0)