this is for problm 46 plz provide better solution