Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for the 'old friend' airplane question #3

Open
jjpn97 opened this issue Dec 6, 2019 · 1 comment
Open

Suggestion for the 'old friend' airplane question #3

jjpn97 opened this issue Dec 6, 2019 · 1 comment

Comments

@jjpn97
Copy link

jjpn97 commented Dec 6, 2019

Hi,

Just want to thank you for creating this doc, certainly helped for my interviews! Thought I should give back by suggesting a slightly easier solution for the airplane question (I think yours has a bit too much going on).

Define p_n = probability of last person in their seat if there are n people. Either the first person goes to their seat (with prob 1/n) and everything's fine, or the first person goes to any seat other than the last, in which case we return to the same problem with n-1 people.

So p_n = 1/n + (n-2)/n p_(n-1). Since p_2 = 1/2 it is simple to use induction to prove p_n = 1/2.

@dwcoder
Copy link
Owner

dwcoder commented Dec 6, 2019

Hi! Thanks for this solution, I have seen a version of it before, and I tried giving this during one of my first interviews. However, the interviewer wanted me to work through all the tedious math I showed in the primer. It actually happened twice to me. That's why it has so much going on. I suggest giving the short, elegant answer that you mention, but be ready to go through the long one as well...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants