Amazon interview question

in the online assessment 2 medium-level leetcode problems