← MathWorks Interview Insights

MathWorks·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Went through a probability-heavy technical screen for a software engineering role at MathWorks. The questions were all math-focused, which I half expected but still felt underprepared for when it came to showing my work clearly.

Questions Asked (3)

Q1

An urn has 5 red and 7 blue balls. If you draw two balls without replacement, what is the probability of getting at least one red ball?

Algorithms & Data Structures
Author's notes

I went with the complement approach: probability of zero reds is (7/12)*(6/11) which gives 42/132, so at least one red is 1 minus that, about 0.682.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use the complement rule: find the probability of drawing no red balls (i.e., two blue balls) and subtract from 1. Alternatively, compute the probability of at least one red directly by summing the cases of one red and two reds. Clearly state the sample space and that draws are without replacement.

Pro tip: Mention that the complement method is often simpler and less error-prone, especially when the event 'at least one' is involved. Also, note that the answer can be verified by computing the direct probability and comparing.

1. Understand the problem

Identify that there are 5 red and 7 blue balls, total 12. Two balls are drawn without replacement. We need P(at least one red).

2. Choose a method

Decide between direct calculation (sum of P(1 red) and P(2 red)) or complement rule (1 - P(0 red)). The complement is usually easier.

3. Compute complement probability

Calculate P(no red) = P(both blue) = (7/12) * (6/11) = 42/132 = 7/22.

4. Apply complement rule

Subtract from 1: P(at least one red) = 1 - 7/22 = 15/22.

5. Verify and present

Optionally verify by direct calculation: P(1 red) = (5/12)*(7/11) + (7/12)*(5/11) = 70/132; P(2 red) = (5/12)*(4/11) = 20/132; sum = 90/132 = 15/22. Present answer clearly.

Key Points to Mention

  • Total number of balls: 12 (5 red, 7 blue).
  • Drawing without replacement means probabilities change after the first draw.
  • Complement rule: P(at least one red) = 1 - P(no red).
  • P(no red) = P(both blue) = (7/12) * (6/11).
  • Simplify fractions correctly (e.g., 42/132 = 7/22).
  • Final answer: 15/22 or approximately 0.6818.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Given the first ball drawn is blue, what is the probability the second ball drawn is red?

Algorithms & Data Structures
Author's notes

Conditional probability, pretty direct.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem setup: ask whether the balls are drawn with or without replacement and the initial counts of blue and red balls. Then, apply conditional probability using the formula P(second red | first blue) = P(first blue and second red) / P(first blue), computing each probability based on the sampling method.

Pro tip: Explicitly state your assumptions about the urn composition and sampling method before calculating—this shows attention to detail and prevents misinterpreting the problem. If the counts aren't given, use variables and express the answer in terms of them.

1. Clarify the setup

Ask for the initial number of blue and red balls, and whether the first ball is replaced before the second draw. Confirm if the draw is random and each ball is equally likely.

2. Define events

Let A be the event that the first ball is blue, and B be the event that the second ball is red. We need P(B|A).

3. Compute probabilities

Calculate P(A) and P(A ∩ B) based on the sampling method. For without replacement, P(A) = B/(B+R) and P(A ∩ B) = (B/(B+R)) * (R/(B+R-1)). For with replacement, P(A) = B/(B+R) and P(A ∩ B) = (B/(B+R)) * (R/(B+R)).

4. Apply conditional probability formula

Use P(B|A) = P(A ∩ B) / P(A). Simplify the expression to get the final probability.

5. State the answer and assumptions

Present the final probability, clearly stating any assumptions made (e.g., without replacement). If variables were used, provide the formula.

Key Points to Mention

  • Conditional probability formula: P(B|A) = P(A ∩ B) / P(A)
  • Difference between sampling with and without replacement
  • Importance of clarifying problem parameters (initial counts, replacement)
  • Calculation of joint probability P(A ∩ B) using multiplication rule
  • Simplification of the final expression
  • Edge cases: e.g., if only one blue ball, probability becomes 0 without replacement

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

What is the expected number of red balls drawn across two draws from the same urn? Walk through the math.

Algorithms & Data Structures
Author's notes

Used linearity of expectation here, which is the right move.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the urn composition and whether draws are with or without replacement. Then use linearity of expectation to compute the expected number of red balls as the sum of the expected reds on each draw, handling dependence if sampling without replacement.

Pro tip: Mention that linearity of expectation holds even when draws are dependent, which is a key insight that simplifies the problem. Also, briefly discuss how the answer changes if the urn composition is unknown, showing awareness of probabilistic nuances.

1. Clarify the problem

Ask for the urn's composition (number of red and non-red balls) and whether draws are with or without replacement. State any assumptions if not provided.

2. Define indicator variables

Let X_i be 1 if the i-th draw is red, 0 otherwise. The total number of red balls is X_1 + X_2.

3. Apply linearity of expectation

Compute E[X_1] and E[X_2] separately. For the first draw, E[X_1] = R/(R+B). For the second draw, if without replacement, E[X_2] = R/(R+B) as well (by symmetry or direct calculation).

4. Sum the expectations

The expected total is E[X_1] + E[X_2] = 2R/(R+B) for both with and without replacement (when the urn has R red and B blue balls).

5. Discuss edge cases and implications

Mention that if the urn composition is unknown, the expected value depends on the prior distribution. Also note that the result generalizes to n draws: n * R/(R+B).

Key Points to Mention

  • Linearity of expectation holds regardless of dependence between draws.
  • For sampling without replacement, the marginal probability of red on the second draw is still R/(R+B).
  • The expected number of red balls in two draws is 2R/(R+B).
  • If the urn composition is unknown, the expected value is the expectation over the prior distribution of R/(R+B).
  • The result extends to n draws: n * R/(R+B).
  • Clarifying assumptions (with/without replacement, known composition) is crucial before solving.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.