Skip to content

add design-1 solutions#2667

Open
nikhylw wants to merge 1 commit into
super30admin:masterfrom
nikhylw:master
Open

add design-1 solutions#2667
nikhylw wants to merge 1 commit into
super30admin:masterfrom
nikhylw:master

Conversation

@nikhylw
Copy link
Copy Markdown

@nikhylw nikhylw commented May 29, 2026

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

Implement Hash Set (design_hashset.py)

Strengths:

  • Good understanding of hash table concepts (chaining with linked lists)
  • Clean separation of concerns with helper methods
  • Proper handling of null storage buckets

Areas for Improvement:

  1. Critical Bug: The getPrev method doesn't properly distinguish between "key found" and "key not found" cases. When the while loop exits because curr == None, you need to check if it was because the key was found (curr.key == key) or because we reached the end of the list.

  2. Dummy Node Key Issue: Using -1 as a dummy key could conflict with valid keys (0 is valid per constraints). Consider using None or a separate isDummy flag.

  3. Time Complexity: The solution has O(n) worst-case time complexity per operation, while the reference solution achieves O(1) average case using a two-level array approach. Consider using a larger number of buckets or a different collision resolution strategy.

  4. Code Clarity: The getPrev method name is misleading since it returns a Node, not a boolean. Consider renaming to findNodeWithPrev or similar.

  5. Edge Cases: The add operation doesn't check if the key already exists before adding, which could lead to duplicates.

VERDICT: NEEDS_IMPROVEMENT


Implement Min Stack (design_min_stack.py)

Strengths:

  • Excellent space optimization by using a single stack instead of two
  • Correct handling of duplicate minimum values
  • Clean, readable implementation
  • Proper use of Python idioms

Areas for Improvement:

  • Consider adding docstrings to explain the algorithm
  • Could add type hints for better code documentation
  • The condition val <= self.min is correct but could be clarified with a comment

Minor Note:
The reference solution uses a separate minSt stack which makes the logic more explicit, but the student's single-stack approach is equally valid and more memory-efficient. Both are accepted solutions for this problem.

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