ML Interview Q Series: Calculating Probability of Three Adjacent Empty Parking Spaces Using Combinations
Browse all the Probability Interview Questions here.
Question: A parking lot has 10 parking spaces in a row. There are 7 cars parked, and each car owner picks at random from the spaces available. Specify an appropriate sample space and determine the probability that the three empty places are adjacent.
Short Compact solution
Take the sample space to be all the ways of choosing 3 distinct empty spots out of 10. This sample space has C(10, 3) equally likely outcomes. The count of ways to choose 3 consecutive spots is 8 (namely positions 1–2–3, 2–3–4, …, 8–9–10). Hence the probability is 8 / C(10, 3) = 1/15.
Comprehensive Explanation
Formulating the Sample Space
When 7 cars occupy 7 of the 10 parking spots, exactly 3 spots remain empty. We treat each way of choosing 3 empty spots as a single outcome in our sample space. Because we assume each car independently picks a spot uniformly at random (without replacement), each combination of 3 empty spots is equally likely. Therefore, the total number of equally likely outcomes in our sample space is:
where 10 is the total number of parking spots, and 3 is the number of empty spots.
In plain text, binom(10, 3) = 10! / (3!(10 - 3)!) = 120.
Counting Favorable Outcomes
We want the 3 empty spots to be adjacent to each other. In a row of length 10, there are exactly 8 ways to pick 3 consecutive spots:
(1, 2, 3)
(2, 3, 4)
(3, 4, 5)
(4, 5, 6)
(5, 6, 7)
(6, 7, 8)
(7, 8, 9)
(8, 9, 10)
Hence there are 8 favorable outcomes.
Final Probability
The probability that the three empty spots are adjacent is simply the ratio of favorable outcomes to total outcomes:
Hence the probability is 1/15.
Why an Unordered Sample Space?
It might initially seem that we should consider order (like permutations). However, because each of the 7 cars picks a random place among those unoccupied, the end result depends only on which spots remain empty, not in which order the empty spots were chosen. Thus, each set of 3 empty spots is equally likely, and an unordered sample space (combinations) is most appropriate.
Potential Pitfalls
Using Permutations Instead of Combinations: One might mistakenly count ordered placements, but since we only care which spots remain unoccupied, order does not matter.
Forgetting Boundary Cases: A common counting mistake is to forget that (1,2,3) and (8,9,10) are valid consecutive triplets as well.
Misinterpretation of “Random”: We assume that each of the 7 cars picks a spot uniformly from what is left; the net effect is equivalent to uniformly choosing any set of 7 spots from the 10 or, equivalently, any set of 3 empty spots from the 10.
Python Snippet to Illustrate
import math
def combinations(n, r):
return math.comb(n, r) # Python 3.8+
total_outcomes = combinations(10, 3) # total combinations
favorable_outcomes = 8
prob = favorable_outcomes / total_outcomes
print(prob) # 0.0666666..., which is 1/15
Additional Follow-Up Question 1
Question: If we considered the order in which cars arrive and park (thus looking at permutations), would the probability still come out to the same value?
Answer Explanation: Yes. Although the total number of ways to arrange 7 cars in 10 spots with order is 10P7 = 10! / 3!, the count of outcomes leading to exactly 3 consecutive empty spots is the number of permutations that leave a specific block of 3 adjacent spots empty. For each block of 3 empty spots, we have 7 distinct spots to place 7 cars in any order, which amounts to 7! ways. Since there are 8 such blocks, the number of favorable permutations is 8 × 7!. Dividing this by 10! / 3! yields the same probability of 1/15. The reason it matches is that the arrangement order does not affect the uniform likelihood of which spots end up empty.
Additional Follow-Up Question 2
Question: What if the cars are not guaranteed to choose all distinct spaces, i.e., the model allows collisions or double parking? Would we still apply the same combinatorial argument?
Answer Explanation: No. If cars can overlap in the same spot, it complicates the counting significantly, because we no longer have exactly 7 distinct occupied spots. The set of empty spots might not even be exactly 3. You would need a different probability model (e.g., each car picks a spot independently with probability 1/10). Then the distribution of the number of cars per spot follows a multinomial or a Poisson approximation for large numbers. The approach given here only holds when exactly 7 distinct spots are occupied.
Additional Follow-Up Question 3
Question: If there were fewer cars than empty spots, say only 2 cars and hence 8 empty spots, how would you compute the probability that a specific arrangement of 8 empty spots has some property?
Answer Explanation: You could again count how many ways the 2 cars can occupy spots among the 10. Specifically, the sample space would be all 2-combinations of 10 spots for the cars (or equivalently 8-combinations for the empty spots). Then to get a particular property of the 8 empty spots (for instance, if you want the empty spots to not include two adjacent positions, or some other condition), count how many of the 2-combinations of spots for cars lead to that arrangement of 8 empties. The reasoning is the same: you carefully enumerate valid empties (or valid placements for cars) and divide by total possible placements of cars.
Additional Follow-Up Question 4
Question: Could we handle more complex adjacency constraints, like “the three empty spots form two separate pairs and a single spot not touching either pair,” using similar combinatorial reasoning?
Answer Explanation: Yes. You would define the sample space the same way (all possible sets of 3 empty spots among 10) and then count the sets matching the condition (for instance, one pair of adjacent empties and one single empty that is not adjacent to that pair). You would systematically enumerate all possibilities that meet the adjacency constraint. While it can get more complicated combinatorially, the general method remains: count favorable outcomes / total outcomes.
Below are additional follow-up questions
Additional Follow-Up Question 1
Question: If each of the 7 cars is considered distinguishable (for instance, by license plate or owner), does this distinction affect the probability that the three empty spaces end up being adjacent? If not, why?
Answer Explanation: Even if each car is unique, the probability of a particular arrangement of 7 occupied and 3 unoccupied spaces in a row is still the same for every set of 3 empty spots. Whether the cars are viewed as identical or distinguishable, the end condition we care about—exactly which three spots are empty—does not change. The total number of possible outcomes can be counted via permutations (10P7) or via the “combination” argument (C(10, 3) for the empty spots). Either approach yields the same probability because every distinct way to seat the 7 individual cars corresponds one-to-one to some combination of empty spots. A potential pitfall is to count permutations incorrectly and forget to divide by the total number of permutations. That would artificially inflate or reduce the count of favorable outcomes. Another real-world subtlety is that if certain cars are more likely to pick certain spots (e.g., bigger cars avoiding tight corners), then “distinguishability” could indeed matter for the actual probability. However, under the uniform-random assumption, distinguishable cars do not alter the final probability of having 3 consecutive empty spaces.
Additional Follow-Up Question 2
Question: How would the analysis change if the parking lot were a circular loop rather than a straight row? Specifically, how many ways are there for the 3 empty spaces to be adjacent on a circular lot of 10 spaces?
Answer Explanation: On a circular lot, space #1 is adjacent to space #10, so the possible “triplets” of empty spots wrap around. In this scenario, the sample space (all ways to choose 3 out of 10 spots to remain empty) remains the same size: C(10, 3). However, the count of “consecutive triplets” is different. In a circle of length 10, there are exactly 10 ways to pick a consecutive triplet (because you can start counting from any of the 10 spots, and the next two are forced). Hence the number of favorable outcomes is 10, rather than 8 for a straight line. The probability would be 10 / C(10, 3) = 10 / 120 = 1/12. A subtlety arises if people generally avoid parking right next to another car on a circular lot. In real-life usage, the assumption of uniform selection might not hold in a loop configuration. That would complicate the calculation further.
Additional Follow-Up Question 3
Question: What if, instead of choosing uniformly at random, each driver has a higher probability of choosing parking spaces near the entrance, or near some other “preferred” location? How would this affect the probability of having three consecutive empty spots?
Answer Explanation: When the probability of choosing each space is not uniform, the chance of any given subset of spots remaining empty is no longer the same for all subsets. This breaks the direct “combination” argument, since not all configurations of 3 empty spots will be equally likely. In that scenario, one must account for the probability distribution that each of the 7 cars uses. For example, if cars are more likely to park close to the entrance, then spots further away might remain empty with greater frequency, raising the odds of consecutive empties in certain distant sections. A standard way to handle this is to compute the probability of each distinct arrangement using the product of the individual choices made by each driver (while also factoring in that once a space is taken, it is no longer available). You then sum the probabilities of those outcomes that have 3 consecutive empty spaces. This can be done via enumerating all possible ways the 7 cars can fill the 10 spaces according to the specific probability distribution, though it becomes complex for large numbers. A pitfall here is to incorrectly assume the unconditional independence of each car’s choice, which would ignore the fact that a spot cannot be chosen if it is already taken.
Additional Follow-Up Question 4
Question: Suppose we care not just about exactly three adjacent empty spaces, but about “at least three consecutive empty spaces somewhere in the row.” Could that affect the counting?
Answer Explanation: Yes. When focusing on “at least three consecutive” rather than “exactly three consecutive,” we must also consider the possibility of four or more consecutive empty spots. Here, the total sample space is still C(10, 3) for 3 empty spots, but if you had, say, 4 empty spaces, you’d want the probability that out of those 4 empties at least three are adjacent. If exactly 3 spaces in total are empty, “at least 3 are consecutive” is the same as “exactly 3 are consecutive.” However, if the number of empty spots is not fixed at 3, or if cars do not fully occupy 7 spots, you would need a more nuanced approach. An important subtlety arises if the number of empty spots can vary (for example, some drivers may leave mid-day, or more may arrive). In that dynamic setting, “at least three consecutive empty spots” can happen in more complicated ways. You would typically model the arrival and departure processes (potentially using queueing theory or Markov chains) rather than a straightforward combinatorial argument.
Additional Follow-Up Question 5
Question: What if the parking lot has multiple rows or tiers, and we only track consecutive empties within each row, ignoring adjacency across rows? Does the same logic extend?
Answer Explanation: For multiple rows or tiers, you would typically treat each row as a smaller 1D problem. If a row has 10 spaces, the probability that exactly 3 of them end up empty and adjacent follows the same approach: C(10, 3) total ways to leave that row partially empty, with 8 ways to place those empties consecutively in a single row. If you have multiple rows, the probability that a given row has 3 consecutive empties can be computed independently if you assume each row’s occupancy is decided separately. However, real-world constraints might connect the rows: for example, if a driver who sees the first row is nearly full chooses to go to the second row. Such dependencies break the simple multiplication of probabilities across rows. Also, if you care about “three consecutive empty spots anywhere in the entire parking system,” you must consider the union of events over different rows, which can be more intricate to calculate. A subtlety is the counting of adjacency in a multi-row design. Sometimes you might consider adjacency across row boundaries (if the physical layout allows it). In that case, you can no longer treat rows independently, because empties that span the boundary between row one and row two might count as adjacent depending on the lot’s layout.