Minimum Moves to Equal Candy Bars
Updated
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) → intExamples
Example 1
A = 1B = 2C = 3return = -1It is not possible to make all candies of the same type with the given operation.
Constraints
1 <= A, B, C <= 10^8
More Walmart interview questions
- Merge a List In Between Two PositionsONSITE INTERVIEW · Seen Nov 2026
- Merge Intervals from Start and End ListsONSITE INTERVIEW · Seen Nov 2026
- Palindrome Check Ignoring SymbolsONSITE INTERVIEW · Seen Nov 2026
- Largest Team Where Every Pair OverlapsOA · Seen Nov 2026
- House RobberOA · Seen Sep 2026
- Maximum Points by Deleting ElementsOA · Seen Sep 2026
- Distinct Bitwise-OR Scores of Increasing SubsequencesOA · Seen Sep 2026
- Best Meeting PointOA · Seen Sep 2026
- Minimum Cost to Make Array EqualOA · Seen Sep 2026
- Minimum Stress PathOA · Seen Aug 2026
Similar questions at other companies
- Last Digit of the Ways to Split Traders Between Two OfficesAkuna Capital · OAAkuna Capital interview questions
- Counting Cows by Their LegsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Summarize Taxi Drivers and RidesBoston Consulting Group · OABoston Consulting Group interview questions
- Total Cost Against the Lowest Earlier PricePayPal · OAPayPal interview questions
- Count Valid Square PairsAuxoAI · OA
- Server InvestmentRippling · OARippling interview questions
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Identification Number Check DigitAbridge · OAAbridge interview questions
- Count Substrings With Identical CharactersVirtu Financial · OAVirtu Financial interview questions
- Next Pascal Row CoefficientIntuit · OAIntuit interview questions