Login

All Problems

Problem title

Difficulty

Avg time to solve

Car Pooling

Moderate

30 mins

Most Frequent Word

Easy

--

Print Strobogrammatic Numbers

Moderate

25 mins

Busy Ninja

Moderate

20 mins

Maximum Sum

Easy

20 mins

Batch Photography

Hard

30 mins

Maximum Number Of Eaten Apples

Moderate

15 mins

Climbing the leaderboard

Moderate

15 mins

MaxFrequencyStack

Hard

45 mins

Deletion in Circular Linked List

Easy

--

Problem

Submissions

0

Avg. time to solve

20 min

Success Rate

80%

Problem Statement

```
N = 3
A = [ 1, 2, 1 ]
Explanation :
The rearrangements of array ‘A’ can be [ 1, 1, 2] , [ 1, 2, 1] and [ 2, 1, 1].
The sum for [ 1, 1, 2 ] is 0*1 + 1*1 + 2*2 = 5.
The sum for [ 1, 2, 1 ] is 0*1 + 1*2 + 2*1 = 4.
The sum for [ 2, 1, 1 ] is 0*2 + 1*1 + 2*1 = 3.
The maximum among these is 3.
```

```
The first line contains an integer 'T' which denotes the number of test cases to be run. Then the test cases follow.
The first line of each test case contains an integer ‘N’.
The next line contains ‘N’ integers representing the elements of array ‘A’ .
```

```
For each test case, output an integer denoting the maximum sum.
Print the output of each test case in a new line.
```

```
You don’t need to print anything. It has already been taken care of. Just implement the given function.
```

```
1 <= T <= 5
2 <= N <= 10^5
1 <= A[i] <= 10^5
Time Limit : 1 sec
```

```
2
2
1 1
3
1 2 3
```

```
1
8
```

```
For test case 1 we have,
The sum of [ 1, 1 ] = 0*1 + 1*1 = 1.
There is no other rearrangement possible.
So, we output 1.
For test case 2 we have,
The maximum sum rearrangement is [ 1, 2, 3 ] with sum 0*1 + 1*2 + 2*3 = 8.
Hence, we output 8.
```

```
2
2
7 2
5
4 1 7 5 1
```

```
7
52
```

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Language

Change Theme

Solution submission not allowed

Save Code

Reset Code