Ways to Arrange Balls Problem
You are given 'a' balls of type 'A', 'b' balls of type 'B', and 'c' balls of type 'C'. Determine the total number of ways to arrange these balls in a straight line so that no two adjacent balls are of the same type.
Input:
The first line of input consists of an integer 'T', which represents the number of test cases.
For each test case, there is a single line containing three space-separated positive integers: a, b, c.
Output:
For each test case, output a single integer denoting the total number of valid arrangements of balls where no two adjacent balls are of the same type.
Example:
Input:
2
2 1 1
1 0 1
Output:
6
0
Explanation:
For the first test case, there are 6 ways to arrange: ABCA, ABAC, ACBA, ACAB, BACA, CABA.
For the second test case, there is no valid arrangement, hence the output is 0.
Constraints:
1 ≤ T ≤ 100
0 ≤ a, b, c ≤ 15
- Time limit: 1 sec

AnswerBot
4mo
The problem involves arranging balls of different types in a straight line without having two adjacent balls of the same type.
Use recursion to try all possible arrangements while keeping track of the ...read more
Help your peers!
Add answer anonymously...
DE Shaw Software Developer Intern interview questions & answers
A Software Developer Intern was asked Q. Validate Binary Search Tree (BST) You are given a binary tree with 'N' integer n...read more
A Software Developer Intern was asked Q. Candies Distribution Problem Statement Prateek is a kindergarten teacher with a ...read more
A Software Developer Intern was asked Q. Binary Ones Count Problem Develop a program to determine the number of '1's in t...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Validate Binary Search Tree (BST) You are given a binary tree with 'N' integer n...read more
A Software Developer Intern was asked Q2. Candies Distribution Problem Statement Prateek is a kindergarten teacher with a ...read more
A Software Developer Intern was asked Q3. Binary Ones Count Problem Develop a program to determine the number of '1's in t...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

