• Emily Zhang
  • Fiddler

Can You Ace the Technical Interview?

2024 May 312024 May 31 Problem Back

This Week's Fiddler

Let the expected value of the desired sum of a line segmnent of length LLL be f(L)f(L)f(L), which is defined recursively as:

f(L)=1L∫0L(x(L−x)+f(x)+f(L−x)) dxf(L)=1L∫0L(Lx−x2) dx+1L∫0L(f(x)+f(L−x)) dxf(L)=1L[12Lx2−13x3]x=0L+1L∫0L(f(x)+f(L−x)) dxf(L)=1L(12L3−13L3)+1L∫0L(f(x)+f(L−x)) dxf(L)=16L2+1L∫0L(f(x)+f(L−x)) dxf(L)=\frac{1}{L}\int_0^L{\Big(x(L-x)+f(x)+f(L-x)\Big)\ dx} \\ f(L)=\frac{1}{L}\int_0^L{(Lx-x^2)\ dx}+\frac{1}{L}\int_0^L{\Big(f(x)+f(L-x)\Big)\ dx} \\ f(L)=\frac{1}{L}\Big[\frac{1}{2}Lx^2-\frac{1}{3}x^3\Big]_{x=0}^L+\frac{1}{L}\int_0^L{\Big(f(x)+f(L-x)\Big)\ dx} \\ f(L)=\frac{1}{L}\Big(\frac{1}{2}L^3-\frac{1}{3}L^3\Big)+\frac{1}{L}\int_0^L{\Big(f(x)+f(L-x)\Big)\ dx} \\ f(L)=\frac{1}{6}L^2+\frac{1}{L}\int_0^L{\Big(f(x)+f(L-x)\Big)\ dx}f(L)=L1​∫0L​(x(L−x)+f(x)+f(L−x)) dxf(L)=L1​∫0L​(Lx−x2) dx+L1​∫0L​(f(x)+f(L−x)) dxf(L)=L1​[21​Lx2−31​x3]x=0L​+L1​∫0L​(f(x)+f(L−x)) dxf(L)=L1​(21​L3−31​L3)+L1​∫0L​(f(x)+f(L−x)) dxf(L)=61​L2+L1​∫0L​(f(x)+f(L−x)) dx

Due to symmetry between xxx and L−xL-xL−x from x=0x=0x=0 to x=Lx=Lx=L, we can rewrite this as:

f(L)=16L2+∫0L2Lf(x) dxf(L)=\frac{1}{6}L^2+\int_0^L{\frac{2}{L}f(x)\ dx}f(L)=61​L2+∫0L​L2​f(x) dx

Expanding the recursive definition, we get:

f(L)=16L2+∫0L2L(16x2+2x∫0xf(y) dy) dxf(L)=16L2+19L2+∫0L∫0x4Lxf(y) dy dxf(L)=\frac{1}{6}L^2+\int_0^L{\frac{2}{L}\Big(\frac{1}{6}x^2+\frac{2}{x}\int_0^x{f(y)\ dy}\Big)\ dx} \\ f(L)=\frac{1}{6}L^2+\frac{1}{9}L^2+\int_0^L{\int_0^x{\frac{4}{Lx}f(y)\ dy}\ dx}f(L)=61​L2+∫0L​L2​(61​x2+x2​∫0x​f(y) dy) dxf(L)=61​L2+91​L2+∫0L​∫0x​Lx4​f(y) dy dx

Continuing one more step:

f(L)=16L2+19L2+∫0L∫0x4Lx(16y2+∫0y2yf(z) dz) dy dxf(L)=16L2+19L2+227L2+∫0L∫0x∫0y8Lxyf(z) dz dy dxf(L)=\frac{1}{6}L^2+\frac{1}{9}L^2+\int_0^L{\int_0^x{\frac{4}{Lx}\Big(\frac{1}{6}y^2+\int_0^y{\frac{2}{y}f(z)\ dz}\Big)\ dy}\ dx} \\ f(L)=\frac{1}{6}L^2+\frac{1}{9}L^2+\frac{2}{27}L^2+\int_0^L{\int_0^x{\int_0^y{\frac{8}{Lxy}f(z)\ dz}\ dy}\ dx}f(L)=61​L2+91​L2+∫0L​∫0x​Lx4​(61​y2+∫0y​y2​f(z) dz) dy dxf(L)=61​L2+91​L2+272​L2+∫0L​∫0x​∫0y​Lxy8​f(z) dz dy dx

This pattern, though I have no formal proof for it (proof by induction, perhaps?), continues as a geometric series! (Note that the terms approach 0 as we continue recursing.) The initial value is 16L2\frac{1}{6}L^261​L2, and the ratio between terms is 23\frac{2}{3}32​, making the value of f(L)=16L2⋅11−23=12L2f(L)=\frac{1}{6}L^2\cdot\frac{1}{1-\frac{2}{3}}=\frac{1}{2}L^2f(L)=61​L2⋅1−32​1​=21​L2.

Hence, f(1)=12f(1)=\frac{1}{2}f(1)=21​.

Answer: 1/2


Extra Credit

There's a "triangle" of probabilities based on the values of aaa and bbb because a+b≤La+b\le La+b≤L. The area of this triangle is L22\frac{L^2}{2}2L2​, so our double-integral of expected value must be divided by this. Hence, our recursive definition of G(L)G(L)G(L) (the expected value of our sum):

G(L)=2L2∫0L∫0L−a(ab(L−a−b)+f(L−a)+f(L−b)+f(a+b)−f(a)−f(b)−f(L−a−b)) db daG(L)=\frac{2}{L^2}\int_0^L{\int_0^{L-a}{\Big(ab(L-a-b)+f(L-a)+f(L-b)+f(a+b)-f(a)-f(b)-f(L-a-b)\Big)\ db}\ da}G(L)=L22​∫0L​∫0L−a​(ab(L−a−b)+f(L−a)+f(L−b)+f(a+b)−f(a)−f(b)−f(L−a−b)) db da

Using commutivity, we can combine the positive recursive terms into 3f(a+b)3f(a+b)3f(a+b) and combine the negative recursive terms into 3f(a)3f(a)3f(a).

The first non-recursive term is 160\frac{1}{60}601​.

The second non-recursive term is 3200\frac{3}{200}2003​.

Guessing that it's another geometric series, this makes one with a ratio of 910\frac{9}{10}109​, making the final answer 160⋅10=16\frac{1}{60}\cdot10=\frac{1}{6}601​⋅10=61​.

Answer: 1/6

Back to Fiddler list
© 2024 Emily Bradon Zhang·Support Gaza Recovery