Skip to content

Implement Queue and HahsMap#2472

Open
ayushcha2701 wants to merge 2 commits into
super30admin:masterfrom
ayushcha2701:ayush
Open

Implement Queue and HahsMap#2472
ayushcha2701 wants to merge 2 commits into
super30admin:masterfrom
ayushcha2701:ayush

Conversation

@ayushcha2701
Copy link
Copy Markdown

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

Create Queue using Stacks (MyQueue.java)

Strengths:

  • Clean, readable implementation with clear variable naming
  • Correct use of Stack data structure for both input and output stacks
  • Proper handling of edge cases (empty queue)
  • Good comments explaining time/space complexity
  • Efficient sharing of transfer logic between pop() and peek()

Areas for Improvement:

  • Consider adding a helper method for the transfer logic to reduce code duplication between pop() and peek()
  • The empty() method could be simplified to return in.isEmpty() && out.isEmpty(); directly returning the boolean expression instead of using an if-else

VERDICT: PASS


Implement Hash Map (MyHashMap.java)

Strengths:

  1. Clean, well-structured code with good separation of concerns
  2. Correct implementation of HashMap with chaining
  3. Good handling of edge cases (null checks, key not found scenarios)
  4. Clear comments explaining the approach
  5. Efficient average-case time complexity

Areas for Improvement:

  1. The put method has a potential issue: when storage[idx] is null, you create a dummy node with key=-1, but if the actual key being inserted is -1, this could cause issues. Consider using a different sentinel approach or handling this edge case.
  2. Variable naming could be more consistent (mix of 'idx' and 'index')
  3. The comment "O(n + 10000)" for space complexity is slightly misleading - it should be O(buckets + n) where buckets=10000

Minor Suggestions:

  • Consider adding null checks in find() method for robustness
  • The dummy node approach is correct but could be documented better

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.

3 participants