Performance Boost for question 1 (Zahi's Algo)