Solution to CTCI 9.1