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
Be the first one to answer
Add answer anonymously...
DE Shaw Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter