Error
|
|
---|---|
@Ibrahim Nash | 5761 |
@blackshadows | 5715 |
@akhayrutdinov | 5111 |
@mb1973 | 4989 |
@Quandray | 4944 |
@saiujwal13083 | 4506 |
@sanjay05 | 3762 |
@marius_valentin_dragoi | 3516 |
@sushant_a | 3459 |
@verma_ji | 3341 |
@KshamaGupta | 3318 |
Complete Leaderboard | |
|
|
@aroranayan999 | 1083 |
@bt8816103042 | 739 |
@SherlockHolmes3 | 444 |
@SHOAIBVIJAPURE | 430 |
@codeantik | 429 |
@shalinibhataniya1097 | 400 |
@ShamaKhan1 | 392 |
@neverevergiveup | 372 |
@amrutakashikar2 | 355 |
@murarry3625 | 350 |
@mahlawatep | 349 |
Complete Leaderboard |
Given an array(0-based indexing), you have to find the max sum of i*A[i] where A[i] is the element at index i in the array. The only operation allowed is to rotate(clock-wise or counter clock-wise) the array any number of times.
Example 1:
Input:
N = 4
A[] = {8,3,1,2}
Output: 29
Explanation: Above the configuration
possible by rotating elements are
3 1 2 8 here sum is 3*0+1*1+2*2+8*3 = 29
1 2 8 3 here sum is 1*0+2*1+8*2+3*3 = 27
2 8 3 1 here sum is 2*0+8*1+3*2+1*3 = 17
8 3 1 2 here sum is 8*0+3*1+1*2+2*3 = 11
Here the max sum is 29
Your Task:
Your task is to complete the function max_sum which takes two arguments which is the array A [ ] and its size and returns an integer value denoting the required max sum.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
Constraints:
1<=N<=104
1<=A[]<1000
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes