Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Make the Equal
MEDIUM
30 mins
Greedy
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Greedy
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Make the Equal

Contributed by
Akhilesh Singh Bhadauria
Medium
yellow-spark
0/80
Avg time to solve 30 mins
Success Rate 34 %
Share
0 upvotes

Problem Statement

You are given an array ‘ARR’ of integers of size ‘N’.

In one operation you can increase ‘N’ - 1 elements of the array by 1 or 2 or 5.

The task is to get all elements equal in the minimum number of operations.

Example:
Input: ‘N’ = 3  ‘ARR’ = [1, 2, 3]

Output: 2
In the First operation we can increase the numbers at index 0, and 1 by 2 which makes the array [3, 4, 3].
In the second operation we increase the numbers at index 0 and 2 by 1 which makes all the elements to [4, 4, 4].
It is the optimal answer and there is no other optimal solution.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1 :
2
3 
1 2 3
5 
5 5 5 5 5

##### Sample Output 1 :

2
0
Explanation Of Sample Input 1 :
For the first test case:-
In the First operation we can increase the numbers at index 0, and 1 by 2 which makes the array [3, 4, 3].
In the second operation, we increase the numbers at index 0 and 2 by 1 which makes all the elements [4, 4, 4].
It is the optimal answer and there is no other optimal solution.


For the second test case:-
All the elements of the array are already equal so there is no operation required.
Sample Input 2 :
2
10
13 15 9 7 12 7 12 11 6 12 
7
12 7 12 14 8 6 14 
Sample Output 2 :
16
12
Reset Code
Full screen
Auto
copy-code
Console