Amazon interview question

Was asked to solve a leetcode question