Loading...
You are given an integer array nums of length n.
Choose a starting index s and an initial value x. A sweep then visits every index exactly once, one per step:
s;The k-th visited index (1-indexed) receives the value x - (k - 1). The sweep succeeds if every index j receives a value of at least nums[j].
Return the minimum x such that, for the best choice of s, the sweep succeeds no matter how the visiting order unfolds.
Input: nums = [5,3,1,6,2,4]
Output: 9
Explanation: Start at index 0 with x = 9. Whatever order the range grows in, every element still receives at least its value; no smaller x can guarantee this from any start.
Input: nums = [7,7]
Output: 8
Explanation: One element is visited second and receives x - 1, so x = 8 is needed.
nums.length ≤105nums[i] ≤109Click "Run" to test with sample cases or "Submit" to run all tests.