Skip to content

Completed Design -1 HashSet - #2696

Open
Cheran021 wants to merge 2 commits into
super30admin:masterfrom
Cheran021:master
Open

Completed Design -1 HashSet#2696
Cheran021 wants to merge 2 commits into
super30admin:masterfrom
Cheran021:master

Conversation

@Cheran021

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Design HashSet (Sample.java)

Strengths:

  • Your solution correctly implements the HashSet using the same 2D array approach as the reference solution
  • The code is clean, well-commented, and uses Swift idioms effectively
  • The "hotel with floors and rooms" analogy in your comments makes the approach easy to understand
  • Proper handling of the edge case for primaryIndex == 0 to accommodate keys up to 10^6
  • Good use of guard statements for early returns

Areas for improvement:

  • Your space complexity comment says O(1), but it should be O(n) where n is the number of unique keys added. The total space used grows with the number of keys, even though each operation is O(1).
  • Consider adding more inline comments to explain the hashing logic for future readers

VERDICT: PASS


Min Stack

It appears you have submitted the solution to a different problem (Design HashSet) instead of the Min Stack problem. The Min Stack problem requires you to implement a stack that can retrieve the minimum element in O(1) time.

To solve Min Stack correctly, you typically need:

  • A main stack to store all elements
  • A secondary stack (or variable) to track the minimum at each level
  • When pushing, also push the current minimum onto the min-tracking stack
  • When popping, pop from both stacks
  • getMin() returns the top of the min-tracking stack

Please re-read the problem statement carefully and submit a solution that actually implements the MinStack class with push, pop, top, and getMin methods. The reference solution uses two stacks - one for the actual values and another to track the minimum at each level.

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