- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Airplane Seat Assignment Probability in C++

Suppose n passengers board an airplane with exactly n seats. If the first passenger has lost the ticket and picks a seat randomly. But after that, the rest of passengers will follow these operations −

Take their own seat written in the ticket if it is still available,

Pick other seats randomly when they find their seat occupied

So we have to find what is the probability that the n-th person can get his own seat? So if the input is 2, then the output will be 0.5. So the second person has a probability of 0.5 to get the second seat (when first person gets the first seat).

To solve this, we will follow these steps −

If n is 1, then return 1, otherwise 0.5

## Example (C++)

Let us see the following implementation to get a better understanding −

class Solution { public: double nthPersonGetsNthSeat(int n) { if (n == 1) return 1; return 0.5; } };

## Input

2

## Output

0.50000

- Related Questions & Answers
- Program to find probability of getting assigned seat for the last person in an airplane after seat shuffling in Python
- Assignment Operators in C++
- Compound Assignment Operators in C++
- Compound assignment operators in C#
- Passing the Assignment in C++
- Subjective Probability Vs. Objective Probability
- Knight Probability in Chessboard in C++
- A matrix probability question in C?
- What are assignment operators in C#?
- Bayes Theorem for Conditional Probability in C/C++
- What is an assignment operator in C#?
- Copy constructor vs assignment operator in C++
- Program to implement seat reservation manager in Python
- How to use an assignment operator in C#?
- Java Assignment Operators

Advertisements