nums
and store it in totalSum
.F(0)
by summing up i * nums[i]
for all i
from 0
to n-1
.maxValue
with the value of F(0)
.F(k)
based on the previous value F(k-1)
using the formula F(k) = F(k-1) + totalSum - n * nums[n-k]
.
b. Update maxValue
if F(k)
is greater than the current maxValue
.maxValue
as the maximum value of the rotation function.