Skip to content

completes all exercises - #2700

Open
49V wants to merge 3 commits into
super30admin:masterfrom
49V:master
Open

completes all exercises#2700
49V wants to merge 3 commits into
super30admin:masterfrom
49V:master

Conversation

@49V

@49V 49V commented Sep 8, 2026

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Design HashSet (Exercise_1.py)

Strengths:

  1. Your solution correctly implements the double hashing technique, matching the reference solution's approach.
  2. You properly identified and handled the edge case for the value 1,000,000 by allocating an extra slot at index 0.
  3. The lazy allocation of secondary arrays is a great optimization that saves memory.
  4. Your code is well-structured with clear helper methods.

Areas for Improvement:

  1. Comments: The extensive comments at the top of the file, while showing your thought process, are too verbose for production code. Consider condensing them into a brief explanation of the approach. Also, avoid self-deprecating language like "No you doofus" - keep comments professional.
  2. Unused variable: self.max_value = 1000000 is declared but never used. You can remove it.
  3. Documentation: Consider adding a brief docstring to each method explaining its purpose and complexity.
  4. Type hints: Good use of type hints in add, but consider adding return type hints to remove and contains for consistency.

VERDICT: PASS


Min Stack (Exercise_2.py)

Your solution is creative and well-thought-out! The approach of storing a reference to the last known minimum in each node is elegant and achieves the same O(1) time complexity as the reference solution's two-stack approach. Here are some observations:

Strengths:

  1. Excellent documentation: Your comments and docstring clearly explain the conceptual approach, edge cases, and constraints analysis. This is a great practice.
  2. Correct logic: The solution correctly handles all operations, including the tricky case of popping the minimum element.
  3. Clean code structure: Using a dataclass for the Node is a nice Pythonic touch.
  4. O(1) time complexity: All operations meet the required time complexity.

Areas for Improvement:

  1. Type hints: Consider using Optional[Node] for fields that can be None:
    from typing import Optional
    
    @dataclass
    class Node:
        value: int
        last_known_lowest_element: Optional['Node'] = None
  2. Method naming: The problem uses val as the parameter name. While value is more descriptive, matching the problem's interface can be helpful for clarity.
  3. Alternative approach: The reference solution uses two stacks (one for values, one for minimums). Your approach is essentially equivalent but uses a linked-list-like structure. Both are valid solutions.

Overall, this is a high-quality solution that demonstrates strong problem-solving skills and good coding practices. Keep up the great work!

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