Please code with explanation for this question