Data Structures & AlgorithmsVery hardProduct placement · Amazon/Microsoft

Over all left rotations of [5, 1, 5, 3, 9, 4], what is the maximum value of Σ i·a[i] (0-based)? (Use R(j) = R(j − 1) + sum − n·a[n − j] to move between rotations in O(1).)

  1. A. 76
  2. B. 52
  3. C. 78
  4. D. 79

Correct answer: D. 79

The rotation values are 76, 79, 58, 61, 52, 79; the maximum is 79. The unrotated array gives 76.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic