Pregunta de entrevista de Google

simple algorithm question about ques and stacks