Python Loop Some Coding Questions Leetcode Problem