Seating arrangement of n boys and girls alternatively around a round table
There are n boys and n (n < 10) girls are to be seated around a round table, in a circle. The task is to find the number of ways in which n boys and n girls can sit alternatively around a round table.
Input: n = 5
Input: n = 1
Explanation: There is only 1 boy and 1 girl.
So there is only one possible arrangement
- First, find the total number of ways in which boys can be arranged on a round table.
No. of ways to arrange boys on table = (n-1)!
- After making boys’ arrangements, now make arrangements for girls. After seating boys, there are n space available between them. So there are n positions and n number of girls.
- So the total number of arrangement in which girls sit between boys are n!.
- Therefore Total number of ways = (number of arrangements of boys) * (number of ways to sit girl among boys) = (n-1)! * (n!)
Below is the implementation of the above approach:
Time complexity: O(n), for iterating over n to calculate factorial.
Auxiliary Space: O(1)