Leetcode Problem On Array Methods Python