Free beta: free to use with daily limits while we build. Join the waitlist for founding-member pricing at launch. Join the waitlist

Sign up free

Lyft interview question

Compute the chance of a Lyft ride home and the chance the commuter also rode to work

Company:
Lyft
Type:
Coding
Difficulty:
Medium
Reported:
October 19, 2026

Problem

A data science statistics screen frames this problem around commute coupons. Each commuter makes two trips a day: to work in the morning and back home in the evening. Let W be the event that a commuter takes Lyft to work and H the event that the commuter takes Lyft home. You are given:

  • p_work = P(W)
  • p_home_if_work = P(H | W), the chance of riding home with Lyft after riding to work with Lyft
  • p_home_if_not = P(H | not W), the chance of riding home with Lyft after getting to work some other way

Compute the marginal probability P(H) that a commuter rides home with Lyft, and the posterior probability P(W | H) that a commuter who rode home with Lyft also rode to work with Lyft. Implement commute_probabilities(p_work, p_home_if_work, p_home_if_not) that returns the pair (P(H), P(W | H)). When P(H) = 0 the posterior is undefined; report that in any clear way (the reference solution returns None).

Example 1

Input: p_work = 0.6, p_home_if_work = 0.7, p_home_if_not = 0.2
Output: (0.5, 0.84)

P(H) = 0.6 * 0.7 + 0.4 * 0.2 = 0.42 + 0.08 = 0.5, and P(W | H) = 0.42 / 0.5 = 0.84.

Example 2

Input: p_work = 0.3, p_home_if_work = 0.9, p_home_if_not = 0.1
Output: (0.34, 0.794118)

P(H) = 0.27 + 0.07 = 0.34, and P(W | H) = 0.27 / 0.34 = 27/34, about 0.794118 (rounded here for display).

Constraints

  • All three inputs are probabilities in [0, 1].
  • Return exact arithmetic results; rounding is only for display.

Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern