Skip to content

Design 2#2452

Open
MeghaN28 wants to merge 2 commits intosuper30admin:masterfrom
MeghaN28:master
Open

Design 2#2452
MeghaN28 wants to merge 2 commits intosuper30admin:masterfrom
MeghaN28:master

Conversation

@MeghaN28
Copy link
Copy Markdown

@MeghaN28 MeghaN28 commented Apr 8, 2026

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

Create Queue using Stacks (QueueFromStack.java)

Strengths:

  • The solution correctly implements the queue using two stacks with the expected time and space complexities.
  • The code is clean and well-organized, with appropriate variable names.
  • The student has provided comments explaining their approach, which shows good practice.

Areas for Improvement:

  • The comments in the code are a bit verbose and could be more concise. For example, the explanation of the two approaches is detailed but might be simplified to focus on the chosen method.
  • The student mentioned "amotized" which should be "amortized" – a minor spelling error.
  • The code does not handle the case when the queue is empty for pop and peek operations. The problem states that all calls to pop and peek are valid, so it's acceptable, but in a real-world scenario, it might be good to consider edge cases (though not required here).

Overall, the solution is correct and efficient.

VERDICT: PASS


Implement Hash Map (MyHashMap.java)

Your solution is well-structured and correctly implements the required functionality. Here are some points to consider for improvement:

  • You correctly use separate chaining with linked lists to handle collisions. Using a prime number for the array size is a good practice to distribute keys evenly.
  • In the put method, you check if the key exists and update the value, which is efficient. Similarly, in get and remove, you break early when the key is found.
  • However, note that the problem says "without using any built-in hash table libraries". While LinkedList is allowed (as it's not a hash table), you should be aware that in some contexts, using built-in collections might be restricted. But for this problem, it's acceptable.
  • The time complexity of your solution is O(n) for each operation in the worst case (when all keys hash to the same bucket). But with a good hash function and array size, it should be O(1) on average. Since the constraints are limited (10^4 calls), it's efficient enough.
  • One optimization: you can avoid creating a new Entry if the key already exists (which you already do). Also, in the remove method, you can use an iterator to remove the element without having to store it in a temporary variable, but your current approach is clear.
  • Consider adding a hash function method to compute the index, which would make the code more modular and easier to change if you decide to use a different hash function.
  • Your code is readable and well-commented. Keep up the good work!

Overall, your solution is correct and efficient for the given problem constraints.

VERDICT: PASS

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