Amazon interview question

Problem solving on hackerrank like leetcode