ML Interview Q Series: Distinct Elevator Floor Probability: Using Permutations and Non-Uniform Choice Models
Browse all the Probability Interview Questions here.
A group of five people simultaneously enter an elevator at the ground floor. There are 10 upper floors. The persons choose their exit floors independently of each other. Specify an appropriate sample space and determine the probability that they are all going to different floors when each person randomly chooses one of the 10 floors as the exit floor. How does the answer change when each person chooses with probability 1/2 the 10th floor as the exit floor and the other floors remain equally likely as the exit floor with a probability of 1/18 each?
Short Compact solution
An ordered sample space can be taken as the set of all 5-tuples (i1, i2, i3, i4, i5), where ik denotes the floor chosen by the k-th person. This sample space has 10^5 total outcomes.
When all 10 floors are equally likely with probability 1/10 for each floor, the probability that all five people choose different floors is:
which evaluates to approximately 0.3024.
When each person chooses the 10th floor with probability 1/2, and each of the other 9 floors with probability 1/18 each, the probability that all five people go to different floors is obtained by considering the number of favorable outcomes in two cases: (1) no one chooses floor 10, and (2) exactly one person chooses floor 10. The result is:
which equals 0.0800.
Comprehensive Explanation
Understanding the scenario
Five people enter an elevator at the ground floor of a building that has 10 upper floors. Each person chooses an exit floor in an independent manner, meaning each individual's choice is unaffected by the choices of the others. We want to determine the probability that all five selected floors are distinct under two different models of how the floors are chosen.
Defining the sample space
The natural sample space is all ordered 5-tuples (i1, i2, i3, i4, i5), where ik is the chosen floor for the k-th person (k = 1, 2, 3, 4, 5). Since there are 10 possible floors for each person, the total number of outcomes is 10^5. Each outcome can be viewed as a coordinate in a 5-dimensional grid, with each coordinate representing one of the 10 possible floors.
Probability when floors are all equally likely
In the first model, each floor is chosen with probability 1/10, independently for each person. Thus, each of the 10^5 outcomes in the sample space is equally likely.
To find the probability that all five exit floors are distinct, we compute how many such outcomes have no floor repeated:
The first person has 10 possible floors to choose from.
The second person then has 9 remaining floors (cannot be the same as the first).
The third person has 8 floors, the fourth has 7 floors, and the fifth has 6 floors.
The total number of ways (favorable outcomes) for all five to end up on different floors is 10 × 9 × 8 × 7 × 6. Since the entire sample space has size 10^5, the probability is:
(10 × 9 × 8 × 7 × 6) / (10^5).
Evaluating that fraction gives approximately 0.3024.
Probability when floor 10 is chosen with probability 1/2
In the second model, each person independently chooses floor 10 with probability 1/2 and each of the other 9 floors with probability 1/18. Although the sample space remains the same set of 5-tuples, the probability distribution is no longer uniform. An outcome with exactly r people choosing floor 10 and 5-r people choosing among floors 1 through 9 has probability (1/2)^r × (1/18)^(5-r).
We want the five floors to be distinct. This can happen only under two conditions:
No one chooses floor 10, and all five distinct floors are among the 1 through 9.
Exactly one person chooses floor 10, and the other four choose distinct floors among the remaining 9 floors.
First case (no one chooses floor 10):
There are 9 × 8 × 7 × 6 × 5 ways to pick five different floors out of floors 1 through 9. This count is 15,120.
The probability each person avoids floor 10 is (1/18) for each choice, so each specific 5-tuple (all distinct from 1..9) has probability (1/18)^5. Multiplying 15,120 by (1/18)^5 gives the contribution to the event that all five floors are distinct and floor 10 is not chosen.
Second case (exactly one person chooses floor 10):
Choose which of the five people goes to floor 10. That is (5 choose 1) = 5 ways to decide who picks the 10th floor.
The other four distinct floors must be chosen from floors 1..9. That count is 9 × 8 × 7 × 6 = 3024. Multiplying 5 × 3024 again gives 15,120 as the number of ways.
The probability for exactly one person to pick floor 10 is (1/2) for that person, and (1/18) for each of the other four. Hence each such 5-tuple has probability (1/2) × (1/18)^4. Multiplying 15,120 by that probability gives the second contribution.
Summing the two contributions yields 0.0800.
Hence the probability that all five people exit on different floors in this skewed scenario is significantly lower (0.0800) compared to the uniform 0.3024.
Follow-Up Question: Could the formula change if we considered a different floor with high probability?
If instead of floor 10 having probability 1/2, we assign a different floor, say floor k, with probability p, and the remaining 9 floors share probability (1 - p)/9, then the same principle would apply. We would re-compute:
The probability that no one chooses the special floor k (and all five are distinct among the remaining 9).
The probability that exactly one (or even two, if p were smaller but we still allowed more complex distributions) chooses floor k.
The count of distinct choices among floors 1..9 remains 9 × 8 × 7 × 6 × 5 for five distinct floors. Each 5-tuple has a probability that depends on how many choose the special floor k. The method does not fundamentally change; only the numeric values for p and (1 - p)/9 change.
Follow-Up Question: How do we handle more or fewer people or floors?
The fundamental approach is always the same. For n people and m floors, the sample space has m^n outcomes if each floor is equally likely. If certain floors have different probabilities, the sample space remains m^n but with a non-uniform probability distribution. For the probability that all people select distinct floors in the uniform case, the numerator becomes m × (m-1) × ... × (m-n+1) and the denominator remains m^n. In a non-uniform setting, we sum over all configurations that yield distinct floors, weighted by the product of probabilities for each selected floor.
Follow-Up Question: How could this be implemented in Python?
A direct enumeration for large m and n can be computationally expensive, but for smaller values, a brute-force approach can be demonstrated. For example:
import itertools
def prob_all_distinct(m, n, p_dist):
# p_dist is a list of probabilities of length m
# m floors, n people
# Returns probability that all n chosen floors are distinct
from math import prod
total_prob = 0.0
for combo in itertools.product(range(m), repeat=n):
if len(set(combo)) == n: # distinct
# Probability of this particular outcome
outcome_prob = 1.0
for floor in combo:
outcome_prob *= p_dist[floor]
total_prob += outcome_prob
return total_prob
# Example usage:
# For the uniform case with m=10 and n=5
p_unif = [1/10]*10
print(prob_all_distinct(10, 5, p_unif))
# For the skewed case: floor 9 has prob 1/2, rest floors prob (1-1/2)/9
p_skewed = [1/18]*10
p_skewed[9] = 1/2 # let's label floor 9 as the "special" floor
print(prob_all_distinct(10, 5, p_skewed))
In practice, combinatorial formulas are more efficient and exact. However, enumeration can serve as a helpful validation for smaller problems.
Follow-Up Question: Edge cases and real-world relevance
If more than 10 people are inside the elevator (say 12 people and 10 floors), the probability that all choose different floors would be zero in a strict sense, because at least two people must share a floor. In real-world scenarios, if certain floors are more popular—like a cafeteria on floor 5 or an executive suite on floor 10—the distribution changes. The same mathematical reasoning applies; only the probability distribution over floors is modified to reflect real-world preferences or known patterns of elevator usage.
Below are additional follow-up questions
What if there are correlations between people’s choices?
A potential pitfall is assuming complete independence in each person’s choice of floor. In practice, friends or colleagues often travel together and may end up selecting the same floor intentionally. To account for correlations, you would need to define or estimate a joint probability distribution for their floor selections. Instead of simply taking the product of individual floor probabilities, you would factor in the conditional probabilities that person i picks a certain floor given that person j has already done so.
For instance, if two people are known to work in the same department, you might model an increased likelihood that they choose the same floor. Mathematically, you might have a joint distribution P(i1, i2, i3, i4, i5) that is no longer equal to the product of P(i1) × P(i2) × ... × P(i5). In that case, the enumeration or combinatorial approach still applies, but each 5-tuple must be weighted with the correct joint probability. The main challenge becomes accurately modeling these dependencies.
How would we modify the analysis if the elevator has fewer than five floors?
Another subtle case arises if the building does not have enough distinct floors to accommodate each person on a unique floor (for example, three floors for five people). In such situations, the probability that all five people go to different floors is automatically 0. This can be generalized:
If the number of floors (denoted by m) is less than the number of people (denoted by n), the probability of all distinct floors is zero because of the pigeonhole principle.
If m = n (e.g., five floors for five people), the probability of all distinct floors (in the uniform case) simplifies to the permutation count (m! / m^n). But note that if even a slight correlation or bias is introduced, the calculation of that probability must reflect the new distribution.
How could real-life wait times or elevator capacity affect probabilities?
In real-world scenarios, people’s choices might be influenced by elevator crowding or expected wait times. For example, if they know floor 10 is popular and the elevator might be slower, a person in a hurry could choose a nearby floor to switch to another route. These considerations introduce more complexities:
Individuals might condition their choice on the perceived crowding of certain floors.
The sample space still consists of 5-tuples, but with an altered probability distribution that depends on dynamic factors such as how many people are already “aiming” for a certain floor.
A practical approach might involve agent-based simulation where each new rider updates their probability distribution based on current conditions (i.e., a dynamic model rather than a fixed distribution).
How do we handle partial knowledge of the distribution?
In many cases, you may only have an approximate or incomplete understanding of each person’s probabilities for choosing a given floor. A few ways to address this include:
Using Bayesian updating: start with a prior distribution for each person’s floor choice (perhaps uniform or derived from historical data) and update that distribution as additional context becomes available (for instance, if you know certain departments are on certain floors).
Performing sensitivity analysis: vary your assumptions about the probability distribution to see how robust the probability of all-distinct floors is to changes in the underlying model. If your conclusion remains stable across a range of distributions, you have more confidence in the result.
What if the probability of picking certain floors is time-dependent?
In real-life buildings, the time of day can drastically affect which floors are popular—morning rush to office floors, lunch rush to cafeteria floors, evening rush to ground-floor exits, and so forth. A single static probability distribution may be insufficient. Instead, you might define a time-dependent probability model P(i, t), where for each time slot t, floor i has a different probability. The calculation then needs to consider the exact time window when the five people enter the elevator. If they do so in a short time span where probabilities remain consistent, then a single distribution suffices. If the scenario spans multiple time intervals, you could integrate across the varying probabilities.
What if we need the distribution of how many floors get chosen, rather than just “all distinct”?
Sometimes the question is not simply whether all floors differ, but also how many unique floors end up being selected. You might want the probability that exactly k distinct floors are selected for k = 1, 2, ..., 5. In that case, you would:
Enumerate all 5-tuples,
Count the number of distinct floors in each tuple,
Accumulate the total probability for each value of k. This generalization can be valuable if you care about the broader pattern of floor usage rather than a single event of “all distinct.”
What if people change their minds mid-way?
Although somewhat unusual for a purely mathematical puzzle, it’s possible that a person might decide on one floor, hear from another that it’s overcrowded, and press a different button. This scenario would require modeling not just a single choice per person, but a sequence of choices with probabilities evolving over time. You might represent this as a sequence of states in a Markov chain, or more simply as a revised distribution once new information is revealed. The concept of “distinct floors” would have to be defined carefully—maybe it’s the final set of floors after everyone presses the button for the last time.
How might continuous distributions arise in an analogous problem?
Although this particular puzzle deals with discrete floors, sometimes a similar question appears in a continuous setting. For example, consider five random points placed on a continuous interval [0, 1]. The question becomes: what’s the probability that all five points lie in different “segments” if the interval is subdivided in some manner? The discrete solution doesn’t carry over directly, but the principle of counting or measuring distinct outcomes has a continuous analogue using methods like order statistics. This highlights how the discrete approach can inspire or be adapted to more complex continuous problems, but the math changes to integrals and density functions rather than finite permutations.
How do we interpret “going to different floors” if some floors are restricted or inaccessible?
In certain buildings, certain floors might be inaccessible without a key card, or some floors might be service floors only. If the five people do not all have the same level of access, the distribution of feasible floors changes for each individual. You’d need to tailor each person’s probability distribution by the floors they can access. One person might have 10 possible floors, another might only have 8. This modifies both the sample space (person k has mk feasible floors) and the probability distribution. The probability that all five choose different floors must then be computed accordingly by considering all feasible combinations. The complexity arises because not everyone has the same floor set to choose from, so the enumerations and probabilities can differ by individual.
How does knowledge of certain partial outcomes affect the probability of remaining people’s distinct choices?
Finally, suppose we know that two specific individuals have already chosen distinct floors. We might be asked: “Given that persons 1 and 2 have chosen distinct floors, what is the probability that persons 3, 4, and 5 also choose floors different from those two and different from one another?” This is a conditional probability scenario. We would:
Condition on the event that the first two floors are distinct.
Recompute the probability that the remaining three picks do not overlap with the first two and remain mutually distinct. It’s a common interview question designed to test conditional probability reasoning. You would use P(A ∩ B) / P(A) style arguments, or recast the problem as “Two floors are already taken; how many floors remain for the next person?” The underlying mechanics remain permutations and partial enumerations, but you carefully restrict the sample space to reflect the known conditions.