Skip to content

S30 FAANMG Problem #4 | Create Queue using Stacks#2446

Open
sandy7907 wants to merge 1 commit intosuper30admin:masterfrom
sandy7907:master
Open

S30 FAANMG Problem #4 | Create Queue using Stacks#2446
sandy7907 wants to merge 1 commit intosuper30admin:masterfrom
sandy7907:master

Conversation

@sandy7907
Copy link

No description provided.

@super30admin
Copy link
Owner

  • The solution is correct and efficient. It correctly implements a queue using two stacks with amortized O(1) time for operations.

  • The code is readable and well-structured.

  • However, there is a syntax error: the class is missing a closing brace. This would cause a compilation error. Please add a closing brace at the end of the file.

  • Additionally, to avoid code duplication, you can consider having the pop method call the peek method to ensure the outStack is updated, and then pop. For example:

    public int pop() {
        peek(); // This ensures outStack has the front element if available
        return outStack.pop();
    }
    

    This way, the transfer logic is only in peek. But the current approach is also acceptable.

Overall, the solution is good except for the missing brace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants