Completed Problem 4 (Brute Force)