Skip to content

Python implementation - queue using stack + hashmap design#2441

Open
shaikhmisrail wants to merge 2 commits intosuper30admin:masterfrom
shaikhmisrail:si-design2
Open

Python implementation - queue using stack + hashmap design#2441
shaikhmisrail wants to merge 2 commits intosuper30admin:masterfrom
shaikhmisrail:si-design2

Conversation

@shaikhmisrail
Copy link

No description provided.

@super30admin
Copy link
Owner

Strengths:

  1. The solutions are correct and efficient, meeting the problem requirements.
  2. The code is well-structured and readable, with comments explaining the approach and complexity.
  3. For the queue problem, the amortized O(1) operations are implemented correctly.
  4. For the hashmap problem, the use of separate chaining and a dummy node handles collisions and edge cases effectively.

Areas for Improvement:

  1. In the hashmap problem, the getPrev method might be confusingly named because it returns the node before the target key (if found) or the last node in the list (if not found). Consider renaming it to something like find_previous_node or adding a comment to clarify its behavior.
  2. The hashmap initialization uses a list of size 10000, which is acceptable, but it might be better to use a prime number for the bucket size to reduce collisions. However, this is not critical given the constraints.
  3. In the queue problem, the pop method could call peek to ensure outStack has elements, which might make the code slightly more concise (as in the reference solution). However, the current implementation is also correct.

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