← Bnp Interview Insights

Bnp·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

BNP data scientist interview that leaned pretty heavily on probability and stochastic processes. The coin toss pattern question took up most of the session and went in two parts, theory first then specific computation.

Questions Asked (2)

Q1

Walk through a general method for computing the expected number of fair coin tosses needed before a given length-3 pattern appears as a consecutive run.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I went with the Markov chain approach, setting up states based on how much of the pattern you've already matched.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by framing the problem as a Markov chain with states representing the longest suffix of the toss sequence that matches a prefix of the target pattern. Then set up expected hitting time equations for each state and solve them, using symmetry or pattern-specific properties to simplify. Finally, verify the result with a known formula or simulation for a specific pattern like HHH or HTH.

Pro tip: Mention that the expected waiting time depends on the pattern's autocorrelation structure, and that patterns with overlapping prefixes (like HTH) have longer waiting times than those without (like HHH). This shows you understand the nuance beyond just applying a formula.

1. Define states based on pattern prefixes

Identify the states as the length of the longest suffix of the current sequence that is also a prefix of the target pattern. For a length-3 pattern, there are typically 4 states: 0, 1, 2, and 3 (absorbing).

2. Set up expected hitting time equations

Let E_i be the expected number of additional tosses to reach state 3 from state i. Write equations: E_3 = 0, and for i < 3, E_i = 1 + (1/2)E_{next if H} + (1/2)E_{next if T}, where next states depend on the pattern.

3. Solve the linear system

Solve the system of linear equations for E_0, the expected waiting time from scratch. Use substitution or matrix methods, and simplify using the specific pattern's transition structure.

4. Interpret and validate the result

Check that the answer is reasonable (e.g., for HHH it's 14, for HTH it's 10). Optionally, mention that the general formula involves the autocorrelation polynomial or use a simulation to verify.

Key Points to Mention

  • Markov chain states represent the longest suffix matching a pattern prefix.
  • Expected hitting time equations: E_i = 1 + average of next states' expectations.
  • The pattern's autocorrelation (overlaps) affects the expected waiting time.
  • For fair coin, each transition has probability 1/2.
  • Solving the linear system yields the expected number from state 0.
  • Known results: E[HHH]=14, E[HTH]=10, E[HTT]=8, illustrating pattern dependence.

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

Q2

Compute the expected number of tosses for the pattern HHH, and separately for HTH.

Algorithms & Data StructuresProduct Analytics & Metrics
Author's notes

HHH came out to 14, which I got right.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use Markov chain states to represent the progress toward the target pattern, set up equations for expected additional tosses from each state, and solve them. For HHH, states are 0, H, HH; for HTH, states are 0, H, HT. Alternatively, use martingale or pattern overlap arguments for a quicker solution.

Pro tip: Mention that the expected waiting time for a pattern can be computed as the sum of 2^k over all k where the pattern has a border of length k (i.e., a proper prefix that is also a suffix). For HHH, borders at k=1,2,3 give 2+4+8=14; for HTH, only k=3 gives 8. This shows deep understanding and avoids lengthy derivations.

1. Define states based on progress

Identify the relevant states representing how much of the target pattern has been matched so far. For HHH: states 0, H, HH. For HTH: states 0, H, HT.

2. Set up expected value equations

Let E_s be the expected number of additional tosses to reach the target from state s. Write equations based on the next toss: e.g., from state 0, E_0 = 1 + 0.5 E_0 + 0.5 E_H (for HHH).

3. Solve the system of equations

Solve the linear equations to find E_0 for each pattern. For HHH, equations yield E_0 = 14. For HTH, equations yield E_0 = 10.

4. Verify using pattern overlap formula

Check results using the formula: expected waiting time = sum_{k in borders} 2^k, where borders are lengths of proper prefixes that are also suffixes. For HHH: borders at 1,2,3 -> 2+4+8=14. For HTH: border at 3 -> 8, but note that the formula gives 8? Actually, the correct formula for expected waiting time is sum_{k in borders} 2^k, but for HTH, the borders are only k=3 (since HTH has no proper prefix that is also a suffix except the full string? Wait, HTH: proper prefixes: H, HT; suffixes: H, TH. H is a prefix and suffix? Yes, H is a prefix and also a suffix (the last character is H). So border length 1? Actually, a border is a string that is both a proper prefix and a proper suffix. For HTH, proper prefix 'H' and proper suffix 'H' match, so border length 1. Also, proper prefix 'HT' and proper suffix 'TH' do not match. So borders: length 1 and length 3? But length 3 is the full string, not proper. So only border length 1. Then sum 2^1 = 2, which is not 10. So the formula is not simply sum 2^k for borders. The correct formula for expected waiting time for a pattern is sum_{k in borders} 2^k, where borders include the full pattern? Actually, the known result: expected waiting time for pattern w is sum_{k in B} 2^k, where B is the set of lengths of borders of w, including the full length. For HHH, borders: lengths 1,2,3 -> 2+4+8=14. For HTH, borders: length 3 only? But HTH has a border of length 1? Let's check: proper prefix of length 1 is 'H', proper suffix of length 1 is 'H' -> yes, border length 1. Also, full length 3 is a border? The full string is not a proper border, but in the formula, we include the full length. So borders: 1 and 3 -> 2+8=10. Yes! So the formula includes the full length as a border. So for HTH, borders at 1 and 3 -> 2+8=10. For HHH, borders at 1,2,3 -> 2+4+8=14. So the formula works. So in step 4, verify using the formula: expected waiting time = sum_{k in borders} 2^k, where borders include the full length. For HHH: 2+4+8=14. For HTH: 2+8=10.

Key Points to Mention

  • Markov chain states represent progress toward the pattern.
  • Expected value equations are set up by conditioning on the next toss.
  • Solving linear equations yields E[HHH]=14 and E[HTH]=10.
  • Pattern overlap (borders) affects expected waiting time: HHH has more self-overlap, leading to longer wait.
  • The formula E = sum_{k in borders} 2^k (including full length) provides a quick check.
  • Interpretation: HHH takes longer because after a failure, you may lose more progress.

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