Question d’entretien chez Micro Focus

given an array , while parsing it following operations were performed at each element on an initially empty stack and queue: - empty the contents of the stack into the queue - push the current element of the array on the the stack - empty the queue and push the element onto the stack the stack should be returned after parsing the array completely.

Réponse à la question d'entretien

Utilisateur anonyme

14 oct. 2020

Since we are putting the elements of the stack onto the queue and the taking the back , we're effectively reversing the stack at each iteration hence the ends to which the element gets attached depends only on the parity of the index.