Skip to content

Implement hash set and min stack#2673

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

Implement hash set and min stack#2673
ayushcha2701 wants to merge 2 commits into
super30admin:masterfrom
ayushcha2701:ayush-hashSet

Conversation

@ayushcha2701
Copy link
Copy Markdown

No description provided.

@ayushcha2701 ayushcha2701 changed the title Implement hash set- Implement hash set and min stack Jun 3, 2026
@super30admin
Copy link
Copy Markdown
Owner

Implement Hash Set (MyHashSet.java)

Strengths:

  • Correct implementation of the double hashing technique
  • Proper lazy initialization of secondary arrays
  • Good handling of edge case for index 0 (arraySize2+1)
  • Clean and readable code structure
  • Consistent naming conventions

Areas for Improvement:

  • The comment section at the top is empty. Consider adding a brief explanation of the approach and complexity analysis
  • Could add input validation (though not strictly required given constraints)
  • The variable names arraySize1 and arraySize2 could be more descriptive like primaryBuckets and secondaryBuckets

Overall, this is a solid implementation that matches the reference solution in both approach and quality.

VERDICT: PASS


Implement Min Stack (MinStack.java)

Strengths:

  • Good understanding of the problem requirements (O(1) operations).
  • Clean variable naming and structure.
  • Attempted to track minimum with a separate variable.

Areas for Improvement:

  1. Critical Bug: The push method has a logic error. When val <= min, you're pushing both the old minimum AND the new value, but pop() only removes one element. This causes an imbalance. The correct approach is to push only the value, and use a separate tracking mechanism (like the reference solution's minSt auxiliary stack) to maintain minimum history.
  2. Logic Fix: Consider using an auxiliary stack to track minimums at each state, similar to the reference solution. This ensures that when you pop, you can correctly restore the previous minimum.
  3. Testing: The solution would fail the provided example test case. Try tracing through: after push(-2), push(0), push(-3), then pop(), top() would return -2 instead of 0.

VERDICT: NEEDS_IMPROVEMENT

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