Amazon interview question

Has to debug the given codes