Not able to understand logic

Please explain question in details with code