Java Practice Coding Problems Leetcode 1509