Add code for problem posed at Google interview prep.