Smallest Rotation with Highest Score
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given an array nums of length n where 0 <= nums[i] < n. Rotating by k (for 0 <= k < n) moves the first k elements to the end, giving [nums[k], nums[k+1], ..., nums[n-1], nums[0], ..., nums[k-1]].
After rotation, each element that is **less than or equal to its new index** earns one point. The score of the rotation is the total number of points.
Return the rotation k with the highest score. If several rotations tie, return the **smallest** such k. Aim for O(n) time.
Examples
Constraints
- 1 <= nums.length <= 10^5
- 0 <= nums[i] < nums.length
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.