Description
An array A is larger than array B if the first position where they differ has A[i] > B[i]. Given nums and k, return the largest subarray of length k (in lexicographical order).
Examples
Input:
nums = [1,4,5,2,3], k = 3Output:
[5,2,3]Explanation:
[5,2,3] is largest.
Input:
nums = [9,8,7,6,5], k = 2Output:
[9,8]Explanation:
Subarrays of length 2: [9,8], [8,7], [7,6], [6,5]. Comparing lexicographically: [9,8] > [8,7] > [7,6] > [6,5], so [9,8] is the largest.
Input:
nums = [3,1,4,1,5,9,2], k = 1Output:
[9]Explanation:
For subarrays of length 1, the possible values are [3], [1], [4], [1], [5], [9], [2]. The lexicographically largest single element is [9].
Constraints
- •
1 ≤ k ≤ nums.length ≤ 10⁵