Completed Problem 2 (Brute Force Solution)