Python Loop Some Coding Questions Leetcode 1504