IBM interview question

two python codes like leetcode level