Skip to content

Design-2 problems solution#2467

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

Design-2 problems solution#2467
Simranb10 wants to merge 1 commit into
super30admin:masterfrom
Simranb10:master

Conversation

@Simranb10
Copy link
Copy Markdown

Submit solutions for Design-2 problems.

@super30admin
Copy link
Copy Markdown
Owner

Create Queue using Stacks (MyQueue.java)

Strengths:

  • Clean, readable implementation that closely follows the optimal algorithm
  • Good use of code reuse (calling peek() in pop())
  • Appropriate comments explaining time/space complexity
  • Handles edge cases properly (checking empty() before pop())

Areas for Improvement:

  • Consider using Deque<Integer> with ArrayDeque instead of Stack<Integer> since Stack is legacy and uses synchronized methods which are slower
  • Could add null/empty checks in push() for robustness (though not required by problem constraints)

Overall, this is a solid implementation that demonstrates understanding of the two-stack queue technique.

VERDICT: PASS


Implement Hash Map (MyHashSet.java)

Strengths:

  • Good understanding of hash table concepts (double hashing)
  • Clean, readable code structure
  • Proper array initialization with edge case handling (hash1 == 0)
  • Well-commented code

Critical Issues:

  • Wrong problem: You implemented a Hash Set instead of a Hash Map. The problem explicitly requires storing key-value pairs and returning values with get(key).
  • Missing functionality: Your solution lacks the get(key) method that returns the stored value.
  • Wrong class name: Should be MyHashMap, not MyHashSet.

What to fix:

  1. Rename class to MyHashMap
  2. Change storage from boolean[][] to store integer values (e.g., int[][] with -1 as default)
  3. Add put(int key, int value) method
  4. Add get(int key) method that returns the value or -1
  5. Modify add to put that accepts both key and value

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