Adding answer to amazon coding question