Jane Street Interview Question

I was asked to (equivalently) transform binary search tree into array and vice versa. Note that they keep doing gambling with you. You have to bet the number that payoff expectation is positive by your mental math.