For and filtering
Efficient solution