As reported: Texas Instruments SDE on-campus OA (2026): 12 aptitude questions, 18 technical MCQs and 2 coding questions in 40 minutes; this was coding question 2. A brute force over all rotations passed within the round's limits.
You are given an integer array arr of size n. For a rotation of the array, its score is
arr[0]·1 + arr[1]·2 + … + arr[n−1]·n
(each element times its 1-based position). Consider the array and all of its left rotations (n arrangements in total) and return the maximum score.
This is close to LeetCode 396 — Rotate Function, whose weights start at 0 instead of 1.
Example
arr = [3,2,1] -> 13
[3,2,1]:3·1 + 2·2 + 1·3 = 10[2,1,3]:2·1 + 1·2 + 3·3 = 13[1,3,2]:1·1 + 3·2 + 2·3 = 13
Constraints: 1 ≤ n ≤ 10^5; -1000 ≤ arr[i] ≤ 1000. The answer can exceed 32 bits.
Code runner format: one line, arr as a JSON array. Implement maxRotationScore(arr) returning a 64-bit integer; the harness prints it.