Amazon interview question

Straight forward from geeksforgeeks