Maximum Weighted Sum After Left Rotations
Reported by candidates from Motive's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Motive reported this one in January 2026, and it looks scarier than it is. Underneath the rotation wording, it's the classic rotate function problem. You need the max weighted sum across all n left rotations of an array up to 200000 long. Brute force recomputes every rotation and dies on size. The real task is finding how one rotation's sum relates to the next, then sweeping once. If your OA is in a day or two, learn that recurrence and you're done. StealthCoder sits invisibly on your screen as a safety net if your mind goes blank mid-assessment.
The problem
You are given a non-empty integer array nums of length n. For an array a, define its weighted sum as a[0] * 1 + a[1] * 2 +... + a[n - 1] * n. Consider the original array and every array obtained by left-rotating nums. Return the maximum weighted sum among all n rotations. Function maximumWeightedLeftRotation(nums: int[]) → long Examples Example 1 nums = [3,2,1] return = 13 The rotations have weighted sums 10 for [3,2,1], 13 for [2,1,3], and 13 for [1,3,2]. The maximum is 13. Example 2 nums = [8,3,1,2] return = 43 The left rotation [3,1,2,8] has weighted sum 3 + 2 + 6 + 32 = 43, which is the maximum. Example 3 nums = [-5] return = -5 A length-one array has only its original rotation. Constraints 1 <= nums.length <= 200000 -2147483648 <= nums[i] <= 2147483647 Every rotation's weighted sum fits in a signed 64-bit integer.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is a recurrence. Let S be the weighted sum of the current array and T the total of all elements. After one left rotation, the first element a[0] moves from weight 1 to weight n, and every other element drops its weight by 1. So new S = S - T + n * a[0]. Compute the initial sum in O(n), then loop n-1 times, updating S with the element that just moved to the back, and track the max. Total O(n) time, O(1) extra space. Pitfalls: using 32-bit ints (values reach 2^31 and sums need long), forgetting the rotation must be left not right, and initializing max to 0, which breaks when every answer is negative like [-5]. Verify on [3,2,1]: S=10, T=6, next = 10-6+9 = 13. If the recurrence slips away during the live OA, StealthCoder is the hedge that surfaces it.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Maximum Weighted Sum After Left Rotations cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Motive's OA.
Motive reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximum Weighted Sum After Left Rotations FAQ
What's the trick to Maximum Weighted Sum After Left Rotations?+
Derive the update between rotations. Moving the first element to the end changes the sum by n * a[0] - T, where T is the total of the array. Compute the first sum once, then update in O(1) per rotation and keep the maximum. No need to build rotated arrays.
How hard is this Motive OA question really?+
Medium. The code is about ten lines, but you must spot the recurrence. If you've seen the rotate function problem, it's easy. If you haven't, brute force feels natural and times out at n of 200000.
Why do I need 64-bit integers here?+
Values go up to about 2^31 in magnitude and get multiplied by weights up to 200000, then summed. That overflows 32 bits easily. Use long in Java, long long in C++. Python handles it natively. Intermediate updates need 64-bit too.
What edge cases should I test?+
A single element like [-5], which must return -5. All-negative arrays, so don't start your max at 0. Duplicates, and extreme values near the int limits. Also check the example [8,3,1,2] returning 43 to confirm you rotate left, not right.
How do I prepare for this in 48 hours?+
Work out the recurrence by hand on [3,2,1] until it's obvious, then code it once with long arithmetic. Practice the same idea on prefix-style sweeps where one step changes a running total. Skip broad grinding. This pattern is narrow and learnable in an evening.