Amazon interview question

Mostly from Data Structures and Algorithms