Skip to content

Completed Problem 1 - #2695

Open
irrawaddy28 wants to merge 1 commit into
super30admin:masterfrom
irrawaddy28:2026
Open

Completed Problem 1#2695
irrawaddy28 wants to merge 1 commit into
super30admin:masterfrom
irrawaddy28:2026

Conversation

@irrawaddy28

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Design HashSet (Exercise_2.py)

It appears there has been a significant mix-up. The solution you provided is for the "Min Stack" problem, not the "Design HashSet" problem.

To correctly solve the Design HashSet problem, you need to:

  1. Create a MyHashSet class
  2. Implement three methods: add(key), remove(key), and contains(key)
  3. Use a hashing strategy (like the reference solution's two-level bucketing approach, or a simpler approach using a large boolean array since keys are bounded by 10^6)

A simple approach could be:

  • Use a boolean array of size 10^6 + 1
  • add(key): set array[key] = True
  • remove(key): set array[key] = False
  • contains(key): return array[key]

Or a more space-efficient approach using bucketing as shown in the reference solution.

Please resubmit with the correct solution to the Design HashSet problem.

VERDICT: NEEDS_IMPROVEMENT


Min Stack

Strengths:

  • Correct implementation of the two-stack approach
  • Excellent documentation with detailed docstrings explaining the algorithm
  • Good variable naming (main_stack, min_stack)
  • Handles edge cases (empty stack pop)
  • Time and space complexity match the reference solution

Areas for Improvement:

  1. Remove debug print statements: The numerous print() statements throughout the code are debugging artifacts. In production code, these should be removed or replaced with proper logging.

  2. Redundant length variable: The self.length variable is unnecessary since len(self.main_stack) provides the same information. This adds complexity without benefit.

  3. Simplify top() method: The method can be simplified to just return self.main_stack[-1] since the problem guarantees non-empty stacks. The current implementation with val = None and conditional logic is unnecessarily complex.

  4. Consider using len() directly: Instead of maintaining self.length, use len(self.main_stack) for emptiness checks.

  5. The run_min_stack() function: This is fine for testing but should be in a separate test file or under if __name__ == "__main__": guard for better code organization.

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