Skip to content

design hashset#2671

Open
Praniksha123 wants to merge 1 commit into
super30admin:masterfrom
Praniksha123:patch-1
Open

design hashset#2671
Praniksha123 wants to merge 1 commit into
super30admin:masterfrom
Praniksha123:patch-1

Conversation

@Praniksha123
Copy link
Copy Markdown

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

Implement Hash Set (Sample.java)

Strengths:

  • Clean, readable code with good variable naming
  • Correct implementation of two-level hashing
  • Proper handling of edge cases (bucket 0 special case)
  • Consistent code formatting and structure
  • Efficient O(1) operations

Areas for Improvement:

  • The variable name bucketItems could be more descriptive like itemsPerBucket or secondaryBucketSize
  • Consider adding JavaDoc comments for the class and methods to improve documentation
  • The solution is functionally equivalent to the reference and demonstrates good understanding of hash table concepts

VERDICT: PASS


Implement Min Stack

  1. Wrong Problem: You have submitted a solution for "Design HashSet" instead of "Implement Min Stack". Please ensure you read and understand the problem requirements before coding.

  2. Missing Required Implementation: The MinStack class should have:

    • A constructor MinStack()
    • void push(int val) - push element onto stack
    • void pop() - remove top element
    • int top() - return top element
    • int getMin() - return minimum element in O(1) time
  3. For the HashSet problem (if that was intended): Your implementation uses a double hashing approach which is reasonable. However, the bucket sizing could be optimized - using bucketItems = 1001 means you're creating arrays of size 1001 for each bucket, which uses more memory than necessary.

  4. General Advice:

    • Always verify you're solving the correct problem
    • For MinStack, the standard approach uses two stacks: one for actual elements and one to track minimum values at each state
    • Each push should push to both stacks; pop from both; getMin returns top of min stack

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.

2 participants