Moody's interview question

Two coding questions