Pergunta de entrevista da empresa IBM

The SQL was just simple SELECT and GROUP BY, the Python question involves using stacks