All Problems

Problem title

Difficulty

Avg time to solve

Exploring Restaurants

Moderate

35 mins

Encode and Decode

Easy

15 mins

Closest Coprime Ancestor

Hard

50 mins

Find the total number of good Triplets

Moderate

30 mins

Minimum Operations To Make Array Equal

Easy

10 mins

Lexicographically Smallest Subsequence of Distinct Characters.

Easy

20 mins

Remove K Digits

Moderate

25 mins

Can Place Books

Easy

15 mins

Rectangle Area

Ninja

55 mins

NINJA'S INTERVAL

Easy

15 mins

Problem

Submissions

4

Avg. time to solve

10 min

Success Rate

90%

Problem Statement

```
The first line of input contains an integer ‘T’, denoting the number of test cases.
The first line of each test case contains an integer ‘N’, denoting the length of the array.
```

```
For each test case, print the minimum number of operations to make all the elements of the array equal.
Output for each test case is printed on a separate line.
```

```
You do not need to print anything. It has already been taken care of. Just implement the given function.
```

```
1 <= T <= 1000
1 <= N <= 10^9
Time Limit: 1 sec
```

```
Can you do this in constant time and space?
```

```
2
1
3
```

```
0
2
```

```
For the first test case,
Initially, the array ‘ARR’ is [1]. Since the array has only a single element therefore it will require 0 operations to make all array elements equal. So the output is 0.
For the second test case,
Initially, the array ‘ARR’ is [1, 3, 5]. So in the first operation, we will increment element 1 by one and decrement element 5 by one and the updated array will look like [2, 3, 4].
Then we perform a second operation in which we will increment 2 by one and decrement element 4 by one and the updated array will look like [3, 3, 3]. So finally all the elements of the array become equal in 2 operations. So the output is 2.
```

```
2
6
5
```

```
9
6
```

Java (SE 1.8)

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 Theme

Solution submission not allowed

Save Code

Reset Code