Problem · Math

Minimum Moves to Equal Candy Bars

Learn this problem
EasyWalmartOA

Problem statement

We have three candies of different taste. A candies of type 1 B candies of type 2 C candies of type 3.

We can perform the following operation any number of times:

Choose any two candies of different taste and turn them into candies of remaining taste. Suppose, we take candy of type 1 and type 2 then they will be converted to type 3.

Our goal is to ensure that all candies have the same taste. If this condition is not achievable, the print -1, else print, 'n', the minimum number of moves required to do so.

Input Format

The first line contains three space-separated integers denoting the Number of candies of type 1(A), Number of Candies of Type 2(B), and Number of candies of type 3(C)

Output Format

Print n which is the minimum number of moves required if the goal is achievable.

If goal is not achievable print -1.

Constraints

1<=A,B,C<=10^8

Function

minimumMovesToEqualCandyBars(A: int, B: int, C: int) → int

Examples

Example 1

A = 1B = 2C = 3return = -1

It is not possible to make all candies of the same type with the given operation.

Constraints

1 <= A, B, C <= 10^8

More Walmart problems

drafts saved locally
public int minimumMovesToEqualCandyBars(int A, int B, int C) {
  // write your code here
}
A1
B2
C3
expected-1
checking account