Amazon interview question

Data Structures - Leet Code pattern but different