Given an integer array nums of length n, let arr_k be nums rotated clockwise (to the right) by k positions, and define F(k) = 0 * arr_k[0] + 1 * arr_k[1] + ... + (n - 1) * arr_k[n - 1]. Return the maximum of F(0), F(1), ..., F(n - 1).
Given an integer array nums of length n, let arr_k be nums rotated clockwise (to the right) by k positions, and define F(k) = 0 * arr_k[0] + 1 * arr_k[1] + ... + (n - 1) * arr_k[n - 1]. Return the maximum of F(0), F(1), ..., F(n - 1).
Example 1:
Input: {"nums":[4,3,2,6]}
Output: 26
Constraints:
n=nums.length
1≤n≤105
−100≤nums[i]≤100
The answer fits in a 32-bit integer.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[4,3,2,6]}
n = 4. Each rotation slides every value one slot right, and the last value wraps to slot 0. F(k) weighs each slot by its index.
arr_0 = nums rotated right by 0; F(0) = sum of weight x value