Amazon interview question

DS Algos from leet code