Can You Ace the Technical Interview? 2024 May 31 2024 May 31 Problem BackThis Week's Fiddler
Let the expected value of the desired sum of a line segmnent of length L L L be f ( L ) f(L) f ( L ) , which is defined recursively as:
f ( L ) = 1 L ∫ 0 L ( x ( L − x ) + f ( x ) + f ( L − x ) ) d x f ( L ) = 1 L ∫ 0 L ( L x − x 2 ) d x + 1 L ∫ 0 L ( f ( x ) + f ( L − x ) ) d x f ( L ) = 1 L [ 1 2 L x 2 − 1 3 x 3 ] x = 0 L + 1 L ∫ 0 L ( f ( x ) + f ( L − x ) ) d x f ( L ) = 1 L ( 1 2 L 3 − 1 3 L 3 ) + 1 L ∫ 0 L ( f ( x ) + f ( L − x ) ) d x f ( L ) = 1 6 L 2 + 1 L ∫ 0 L ( f ( x ) + f ( L − x ) ) d x f(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 ) = L 1 ∫ 0 L ( x ( L − x ) + f ( x ) + f ( L − x ) ) d x f ( L ) = L 1 ∫ 0 L ( Lx − x 2 ) d x + L 1 ∫ 0 L ( f ( x ) + f ( L − x ) ) d x f ( L ) = L 1 [ 2 1 L x 2 − 3 1 x 3 ] x = 0 L + L 1 ∫ 0 L ( f ( x ) + f ( L − x ) ) d x f ( L ) = L 1 ( 2 1 L 3 − 3 1 L 3 ) + L 1 ∫ 0 L ( f ( x ) + f ( L − x ) ) d x f ( L ) = 6 1 L 2 + L 1 ∫ 0 L ( f ( x ) + f ( L − x ) ) d x
Due to symmetry between x x x and L − x L-x L − x from x = 0 x=0 x = 0 to x = L x=L x = L , we can rewrite this as:
f ( L ) = 1 6 L 2 + ∫ 0 L 2 L f ( x ) d x f(L)=\frac{1}{6}L^2+\int_0^L{\frac{2}{L}f(x)\ dx} f ( L ) = 6 1 L 2 + ∫ 0 L L 2 f ( x ) d x
Expanding the recursive definition, we get:
f ( L ) = 1 6 L 2 + ∫ 0 L 2 L ( 1 6 x 2 + 2 x ∫ 0 x f ( y ) d y ) d x f ( L ) = 1 6 L 2 + 1 9 L 2 + ∫ 0 L ∫ 0 x 4 L x f ( y ) d y d x f(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 ) = 6 1 L 2 + ∫ 0 L L 2 ( 6 1 x 2 + x 2 ∫ 0 x f ( y ) d y ) d x f ( L ) = 6 1 L 2 + 9 1 L 2 + ∫ 0 L ∫ 0 x Lx 4 f ( y ) d y d x
Continuing one more step:
f ( L ) = 1 6 L 2 + 1 9 L 2 + ∫ 0 L ∫ 0 x 4 L x ( 1 6 y 2 + ∫ 0 y 2 y f ( z ) d z ) d y d x f ( L ) = 1 6 L 2 + 1 9 L 2 + 2 27 L 2 + ∫ 0 L ∫ 0 x ∫ 0 y 8 L x y f ( z ) d z d y d x f(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 ) = 6 1 L 2 + 9 1 L 2 + ∫ 0 L ∫ 0 x Lx 4 ( 6 1 y 2 + ∫ 0 y y 2 f ( z ) d z ) d y d x f ( L ) = 6 1 L 2 + 9 1 L 2 + 27 2 L 2 + ∫ 0 L ∫ 0 x ∫ 0 y Lx y 8 f ( z ) d z d y d x
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 1 6 L 2 \frac{1}{6}L^2 6 1 L 2 , and the ratio between terms is 2 3 \frac{2}{3} 3 2 , making the value of f ( L ) = 1 6 L 2 ⋅ 1 1 − 2 3 = 1 2 L 2 f(L)=\frac{1}{6}L^2\cdot\frac{1}{1-\frac{2}{3}}=\frac{1}{2}L^2 f ( L ) = 6 1 L 2 ⋅ 1 − 3 2 1 = 2 1 L 2 .
Hence, f ( 1 ) = 1 2 f(1)=\frac{1}{2} f ( 1 ) = 2 1 .
Answer: 1/2
There's a "triangle" of probabilities based on the values of a a a and b b b because a + b ≤ L a+b\le L a + b ≤ L . The area of this triangle is L 2 2 \frac{L^2}{2} 2 L 2 , 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 ) = 2 L 2 ∫ 0 L ∫ 0 L − a ( a b ( L − a − b ) + f ( L − a ) + f ( L − b ) + f ( a + b ) − f ( a ) − f ( b ) − f ( L − a − b ) ) d b d a G(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 ) = L 2 2 ∫ 0 L ∫ 0 L − a ( ab ( L − a − b ) + f ( L − a ) + f ( L − b ) + f ( a + b ) − f ( a ) − f ( b ) − f ( L − a − b ) ) d b d a
Using commutivity, we can combine the positive recursive terms into 3 f ( a + b ) 3f(a+b) 3 f ( a + b ) and combine the negative recursive terms into 3 f ( a ) 3f(a) 3 f ( a ) .
The first non-recursive term is 1 60 \frac{1}{60} 60 1 .
The second non-recursive term is 3 200 \frac{3}{200} 200 3 .
Guessing that it's another geometric series, this makes one with a ratio of 9 10 \frac{9}{10} 10 9 , making the final answer 1 60 ⋅ 10 = 1 6 \frac{1}{60}\cdot10=\frac{1}{6} 60 1 ⋅ 10 = 6 1 .
Answer: 1/6
Back to Fiddler list