You are given three integers a, b and c!
Now can you perform either of two operations on them any number of
times.
email.com
Choose two among a, band c, then increase both by 1
• Choose one among a, b and c, then increase it by 2
ashre14
Your task is to minimize the number of operations required to make all of
them equal by repeatedly performing the operations in any order.
Input Format
The first line contains
a
Our C2550
nail.cose integers a, band c.
Format
shreyashre 14.
Print the minimum number of operations required to make a, band call
equal.
Sample Testcase
14.0*0.com
Testcase Input
2 5 4
Testcase Output
2
Answers
Answer:
You are given three integers a, b and c!
Now can you perform either of two operations on them any number of
times.
email.com
Choose two among a, band c, then increase both by 1
• Choose one among a, b and c, then increase it by 2
ashre14
Your task is to minimize the number of operations required to make all of
them equal by repeatedly performing the operations in any order.
Input Format
The first line contains
a
Our C2550
nail.cose integers a, band c.
Format
shreyashre 14.
Print the minimum number of operations required to make a, band call
equal.
Sample Testcase
The java program is to make the elements in the array equal and then calculate the number of times the elements has been increasing.
Explanation:
import java.io.*;
class abc
{
static void printMinOp(int arr[])
{
int arraySum, smallest, arr_size = arr.length;
arraySum = 0;
smallest = arr[0];
for (int i = 0; i < arr_size ; i ++)
{
if (arr[i] < smallest)
smallest = arr[i];
arraySum += arr[i];
}
int minOperation = arraySum - arr_size * smallest;
System.out.println("Minimum Operation = " +
minOperation);
}
public static void main (String[] args)
{
int arr[] = {2,5,4};
printMinOp(arr);
}
}