educative.io

Solution Review: Implement Queue using Stack - Data Structures for Coding

Hi Team,
In Optimizing both enqueue() and dequeue() solution there might be a problem as if we don’t fill on the stack1 after pop operation, it might end up storing more values than the maxSize, as now total capacity available will become stack1.maxSize + stack2.currentsize.

We can’t use the same enqueue metho unless we have the currentSize of bothe the stacks.

Please correct me if I am wrong here.

Thanks
Ajay

Hi @Ajay_Sharma, thank you so much for reaching out to us and pointing out the issue. The issue has been resolved. Please do spare some time to check the updated code and if you still find any issue then please do let me know. Thanks.

@aswad.sohail I just wanted to point out that the max will still be exceeded in the current solution when optimizing both enqueue() and dequeue() and it has not been fixed.