Program to find all possible permutations in which 'n' people can occupy 'r' seats in a theater is discussed here.
N friends are planning to go to a movie. One among them suggested few movies and all others started to discuss and finally they selected a movie. One among them quickly booked their tickets online, to their surprise they are unable to select their seats. All of them got confused. Then anyhow, decided to go to the movie. They rushed to reach the theater on time. Again they are surprised that no one was there in the theater. They are the only people about to watch the movie. There is 'r' number of seats in which, 'n' number persons should sit. In how many ways they can sit inside the theater?
Given the number of people 'n' and the number of seats 'r' as input. The task is to find the different number of ways in which 'n' number of people can be seated in those 'r' number of seats.
Number of people: 5
Number of Rows: 3
The total number of ways in which 'n' people can be seated in 'r' seats = 60.
=5! /(5?3)! = 5! / ( 5 ? 3 )!
= 120 / 2 = 60
Program to find all possible permutations in which n people can occupy r seats in a theater is given below.
Time complexity: O(n)