Given three integers N, X and Y. The task is to find the number of ways to arrange 2*N persons along two sides of a table with N number of chairs on each side such that X persons are on one side and Y persons are on the opposite side.
Note: Both X and Y are less than or equals to N.
Input : N = 5, X = 4, Y = 2
Output : 57600
The total number of person 10. X men on one side and Y on other side, then 10 – 4 – 2 = 4 persons are left. We can choose 5 – 4 = 1 of them on one side in ways and the remaining persons will automatically sit on the other side. On each side arrangement is done in 5! ways. The number of ways is .5!5!
Input : N = 3, X = 1, Y = 2
Output : 108
The total number of person 2*N. Let call both the sides as A and B. X men on side A and Y on side B, then 2*N – X – Y persons are left. We can choose N-X of them for side A in ways and the remaining persons will automatically sit on the other side B. On each side arrangement is done in N! ways. The number of ways to arrange 2*N persons along two sides of a table is .N!N!
Below is the implementation of the above approach :
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Permutations to arrange N persons around a circular table
- Number of triangles formed by joining vertices of n-sided polygon with two common sides and no common sides
- Number of ways a convex polygon of n+2 sides can split into triangles by connecting vertices
- Maximum number of teams that can be formed with given persons
- Count number of triangles possible for the given sides range
- Probability that two persons will meet
- Time taken by two persons to meet on a circular track
- Minimum time required to complete a work by N persons together
- Count number of ways to arrange first N numbers
- Number of ways to arrange a word such that all vowels occur together
- Number of ways to arrange N numbers which are in a range from 1 to K under given constraints.
- Number of ways to arrange a word such that no vowels occur together
- Maximize volume of cuboid with given sum of sides
- Check if it is possible to create a polygon with given n sides
- Find the type of triangle from the given sides
- Find other two sides of a right angle triangle
- Calculate Stirling numbers which represents the number of ways to arrange r objects around n different circles
- Find other two sides and angles of a right angle triangle
- Find all sides of a right angled triangle from given hypotenuse and area | Set 1
- Find area of parallelogram if vectors of two adjacent sides are given