Skip to content

Design-2#2481

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

Design-2#2481
mananrg wants to merge 1 commit into
super30admin:masterfrom
mananrg:master

Conversation

@mananrg

@mananrg mananrg commented Jun 7, 2026

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Create Queue using Stacks (problem1.py)

Strengths:

  • Correct implementation of the two-stack queue pattern
  • Good use of comments explaining array behavior
  • Proper handling of edge cases (empty queue check in pop)
  • Clean and readable code structure

Areas for Improvement:

  • Variable names could be more descriptive (inst/outst vs inStack/outStack)
  • Could add docstrings to methods for better documentation
  • The comment about x=[1,2,3] is a bit confusing and doesn't add much value

The solution is functionally correct and efficient. It demonstrates good understanding of the problem and implements the standard solution pattern effectively.

VERDICT: PASS


Implement Hash Map (problem2.py)

Strengths:

  1. Good attempt at a two-level bucket approach, which is a valid HashMap design
  2. Clear separation of hash functions
  3. Reasonable code structure and readability

Areas for Improvement:

  1. Critical Bug: The hash functions don't align properly. hash2 returns key // 1000, but the secondary array sizes don't match this logic
  2. Performance Issue: Initializing secondary arrays with -1 values in put() causes O(n) operations, not O(1)
  3. Edge Cases: The special case for primaryIndex == 0 creating a larger array is confusing and likely incorrect
  4. Remove Logic: Setting value to -1 instead of actually removing the entry can cause confusion about whether a key exists
  5. Comments: The comment claiming O(1) time complexity is incorrect and misleading

Recommended Fixes:

  1. Ensure hash functions are consistent with array sizing
  2. Consider lazy initialization or use a more efficient data structure for secondary buckets
  3. Fix the alignment between primary and secondary bucket calculations

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