Amazon Interview Question

Has to debug the given codes