Java Practice Questions Leetcode Problem 9