Solved a google interview question