You are given an integer array nums and an index k.
We want to evaluate all subarrays that must include the index k. For any chosen subarray (i, j) where i ≤ k ≤ j, its score is calculated as:
Your task is to determine the highest score obtainable among all such subarrays that contain index k.
The subarray can expand to the left or right, but it must always cover position k.
Input: nums = [3, 1, 5, 6, 2, 4], k = 2
Output: 10
Explanation:
The best subarray is (2, 3) → values [5, 6] Minimum = 5, length = 2 → score = 5 × 2 = 10.
Input: nums = [9, 7, 3, 8, 4], k = 4
Output: 12
Explanation:
The optimal subarray is (3, 4) → values [8, 4] Minimum = 4, length = 2 → score = 8 But (2,4) → values [3,8,4] Minimum = 3, length = 3 → score = 9 The best is (0,4) → min = 3, length = 5 → score 15 → actually max is 15. (Updated example: Output = 15)
Accepted:
Submission: