Whitepages interview question

Medium to fairly difficult dynamic programming algorithm problem.