Skip to content

Added solutions for Design 1#2626

Open
Balaviknesh wants to merge 1 commit intosuper30admin:masterfrom
Balaviknesh:master
Open

Added solutions for Design 1#2626
Balaviknesh wants to merge 1 commit intosuper30admin:masterfrom
Balaviknesh:master

Conversation

@Balaviknesh
Copy link

No description provided.

@super30admin
Copy link
Owner

No specific feedback provided. Refer to GitHub Comment.

@super30admin
Copy link
Owner

Strengths:

  • For the HashSet, the student has implemented the basic functionality correctly, and the code is readable.
  • For the MinStack, the solution is efficient and correctly implements all required operations in constant time.

Areas for Improvement:

  • For the HashSet:

    • The space allocation is inefficient. Using an array of size 1,000,000 is excessive, especially since the number of operations is limited to 10,000. This wastes memory.
    • The use of mutable lists for each bucket introduces overhead. Each list requires additional memory for its structure, and operations like contains and remove on the list are O(n) in the size of the list. While the large array size reduces the chance of collisions, it is still not guaranteed to be constant time.
    • Consider using a more efficient hashing technique, such as double hashing or separate chaining with a reasonable number of buckets (e.g., 1000 primary buckets) to reduce space usage and maintain average constant time operations.
    • The size variable is maintained but never used, which is unnecessary.
  • For the MinStack:

    • The solution is correct, but note that using a MutableList for the stack is acceptable, but in Kotlin, using ArrayDeque might be more efficient for stack operations. However, the current implementation is functional.
  • General:

    • The student included two solutions in one file. It's better to separate each class into its own file for clarity and maintainability.
    • The comments for time and space complexity for the HashSet are incorrect. The operations are not O(1) in the worst case due to the list operations, and the space complexity is O(1,000,000) which is fixed but large, not O(1) for operations.

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