Micro Focus interview question

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.

Interview Answer

Anonymous

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.