396 Rotate Function
Given an array of integersA
and letnto be its length.
AssumeBk
to be an array obtained by rotating the arrayA
kpositions clock-wise, we define a "rotation function"F
onA
as follow:
F(k) = 0 * Bk[0] + 1 * Bk[1] + ... + (n-1) * Bk[n-1]
.
Calculate the maximum value ofF(0), F(1), ..., F(n-1)
.
Note: nis guaranteed to be less than 105.
Example:
Brute Force: (time limit exceeded)
Last updated