Jane Street Interview Question

first was to calculate the tricky expected value the second was for combinatorics