⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 10s17 days 22 hours 20 minutes 10 seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 10s17 days 22 hours 20 minutes 10 seconds.

Sign in to watch this lesson
Algorithms - Recursion, Backtracking and Combinatorics · 4:13
An order book that receives n buys and n fills and may never go negative is a lattice path that never rises above the diagonal. For n = 3, 5 of the 20 paths survive, and the reflection trick explains why: flipping a bad path after its first step above the diagonal pairs it with one of the 15 paths to (2, 4), so C_n = C(2n, n) - C(2n, n-1) = C(2n, n)/(n+1). The survivors become balanced brackets and full binary trees, the (A)B split gives the recurrence, and we finish with the traps (int overflow, 64-bit limits, dividing under a modulus) and the ballot problem.