Maximum Weighted Sum After Left Rotations
Updated
Problem statement
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[]) → longExamples
Example 1
nums = [3,2,1]return = 13The 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 = 43The left rotation [3,1,2,8] has weighted sum 3 + 2 + 6 + 32 = 43, which is the maximum.
Example 3
nums = [-5]return = -5A 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.
More Motive Onsite Interview questions
- Group AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
- Longest Equal-Zero-One SubarrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
- Valid Parenthesis StringPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
- Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Dec 2025
- Target Triplet SumONSITE INTERVIEW · Seen Dec 2025
- Validate IP AddressONSITE INTERVIEW · Seen Dec 2025
- Generate Palindromic PermutationsONSITE INTERVIEW · Seen Dec 2025
- Minimum Swaps to Group Circular OnesONSITE INTERVIEW · Seen Dec 2025
- Staircase Search In A Sorted MatrixONSITE INTERVIEW · Seen Dec 2025
- Search in Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025
Similar questions at other companies
- Retrieve Vectors by Cosine SimilarityHarvey · ONSITE INTERVIEWHarvey interview questions
- Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Maximize the Even-Odd Index Product GapInfosys · ONSITE INTERVIEWInfosys interview questions
- Squirrel Nut Collection Shortest PathAmazon · ONSITE INTERVIEW
- Expected Value of Modified DiceJane Street · ONSITE INTERVIEWJane Street interview questions
- Linear Layer Forward and Backward PassesMeta · ONSITE INTERVIEWMeta interview questions
- Product Total With the Cheapest PromotionInstacart · ONSITE INTERVIEWInstacart interview questions
- Reservoir Sampling with Recorded DrawsStackAdapt · ONSITE INTERVIEWStackAdapt interview questions
- Koko Eating BananasTekion · ONSITE INTERVIEWTekion interview questions
- Dense Vector Dot ProductCerebras · ONSITE INTERVIEW