A homepage has a row of featured slots, and slot i gets i units of attention (later slots are seen more as the user scrolls). The products' values are in nums. The score of an arrangement is the sum of i * value over all slots.
You may rotate nums right by any k from 0 to n - 1 before placing it. Write bestRotationScore(nums) that returns the highest score any rotation can get. Aim for O(n) time.
Input: nums = [1,5,2] Output: 11
Rotating right by 1 gives [2, 1, 5], scoring 0 * 2 + 1 * 1 + 2 * 5 = 11.
Input: nums = [7] Output: 0
The only slot is slot 0, which scores nothing.
1 <= nums.length <= 10^5-100 <= nums[i] <= 100Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #85 Best Rotation Score. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.