1. The array follows 0-based indexing.
2. In one rotation operation, all elements of the array will shift either towards the left or right by one index.
3. The element at the extreme left index (i.e. 0th index) will shift to the 'N-1'th index after applying one left rotation on the array and the rest all the elements will shift to the 'i-1'th index.
4. The element at the extreme right index (i.e. 'N-1'th index) will shift to the 0th index after applying one right rotation on the array and the rest of the elements will shift to the 'i' + 1'th index.
The first line of the input contains an integer 'T' denoting the number of test cases.
The first line of each test case contains the integer 'N', denoting the size of the array.
The second line of each test case contains 'N' space-separated integers denoting the array elements.
The only line of output of each test case should contain an integer, denoting the maximum value of sum(i * ARR[i]).
You don't need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10^2
1 <= N <= 10^4
0 <= ARR[i] <= 10^6
Time Limit : 1sec
It’s important to note that, there are only a finite number of unique arrangments of the array possible after applying rotation operations on the array any number of times. So what we can do is find the sum(i*ARR[i]) for all possible rotations and return the maximum among them.
Here is the algorithm :
It’s important to note that, there are limited arrays possible after applying rotation operations on the array any number of times. Also notice that 1 left rotation = ‘N - 1' right rotations and vice versa, thus we can choose a single type of rotation and fetch all possible arrangments of the given array.
Here is the algorithm :
Merge Two Sorted Arrays Without Extra Space
Three Sum
Ninja And The Strictly Increasing Array
Negative To The End
Sort 0s, 1s, 2s