Python Loop Some Coding Questions Leetcode 150