Ambev interview question

Lógica