Amazon interview question

Subquery for the coding interview