Doubt in my approach

Is this approach alright ? Is there any fault in my code ?